[Twisted-Python] Patch: Make twisted.web.distrib work with twisted.web.vhost

Tom 'Korpios' Tobin korpios at korpios.com
Fri May 16 10:00:46 EDT 2003

Here is a patch to make twisted.web.distrib work with twisted.web.vhost.

As things stand, when twisted.web.vhost calls a virtual host's getChildWithDefault, it ends up calling getChild.  As ResourceSubscription has no getChild, the render call never happens to make the distributed connection.  By returning self, we can make this happen.

On the ResourcePublisher side of things, after being called in this way (e.g. through a virtual host) request's prepath and postpath are a bit off; we fix this in remote_request.

--- distrib.py  Fri May 16 09:41:18 2003
+++ distrib-patched.py  Fri May 16 09:50:01 2003
@@ -174,6 +174,11 @@
             self.publisher.callRemote('request', request).addCallbacks(i.finished, i.failed)
         return NOT_DONE_YET

+    def getChild(self, path, request):
+        """I am a child; I should return myself so render can be called.
+        """
+        return self
 class ResourcePublisher(pb.Root, styles.Versioned):
     def __init__(self, site):
         self.site = site
@@ -191,6 +196,8 @@
         return self

     def remote_request(self, request):
+        if len(request.prepath) > 0:
+            request.postpath.insert(0, request.prepath.pop())
         res = self.site.getResourceFor(request)
         log.msg( request )
         return res.render(request)

Tom "Korpios" Tobin
korpios at korpios.com

More information about the Twisted-Python mailing list