[Twisted-web] [PATCH] Pass context to static.File processors
Alex Levy
mesozoic at polynode.com
Sun Jan 2 17:06:03 MST 2005
Attached are patches for twisted.web2 and nevow which will allow File
processors to take three arguments (path, context, registry). It keeps
backwards-compatibility for processors that take only (path, registry),
mainly because they're a pain to update ;)
I can't find any places where the registry is actually used, but I've
left it in to make backwards-compatibilty easier.
So, anyone's thoughts? Can we put these in?
--
Alex Levy
WWW: http://mesozoic.geecs.org
"Never let your sense of morals prevent you from doing what is right."
-- Salvor Hardin, Isaac Asimov's _Foundation_
-------------- next part --------------
Index: nevow/static.py
===================================================================
--- nevow/static.py (revision 1035)
+++ nevow/static.py (working copy)
@@ -231,9 +231,15 @@
else:
processor = self.processors.get(fpath.splitext()[1])
if processor:
- return (
- inevow.IResource(processor(fpath.path, self.registry)),
- segments[1:])
+ # Pass our context on to all processors (with backwards-compatibility)
+ try:
+ resc = processor(fpath.path, ctx, self.registry)
+ except TypeError:
+ warnings.warn(
+ '%r: File processors now take three arguments (path, context, registry)'
+ % (processor), DeprecationWarning, stacklevel=2)
+ resc = processor(fpath.path, self.registry)
+ return (inevow.IResource(resc), segments[1:])
return self.createSimilarFile(fpath.path), segments[1:]
-------------- next part --------------
Index: twisted/web2/static.py
===================================================================
--- twisted/web2/static.py (revision 12816)
+++ twisted/web2/static.py (working copy)
@@ -203,7 +203,7 @@
def putChild(self, name, child):
self.children[name] = child
- def locateChild(self, request, segments):
+ def locateChild(self, ctx, segments):
r = self.children.get(segments[0], None)
if r:
return r, segments[1:]
@@ -237,9 +237,15 @@
else:
processor = self.processors.get(fpath.splitext()[1])
if processor:
- return (
- processor(fpath.path, self.registry),
- segments[1:])
+ # Pass our context on to all processors (with backwards-compatibility)
+ try:
+ resc = processor(fpath.path, ctx, self.registry)
+ except TypeError:
+ warnings.warn(
+ '%r: File processors now take three arguments (path, context, registry)'
+ % (processor), DeprecationWarning, stacklevel=2)
+ resc = processor(fpath.path, self.registry)
+ return (resc, segments[1:])
return self.createSimilarFile(fpath.path), segments[1:]
More information about the Twisted-web
mailing list