For those paddling about in the Twisted + WSGI-hosted app world (here I'm playing with TurboGears), one thing you may wind up wanting to do is to have your WSGI application be the "default" URL-tree, with only certain sub-trees handled by Twisted. To be more concrete, say you want your URLs to look like this:
/* -> WSGI URL handling for all urls except
/channels -> Twisted long-polling protocol (or Soap, or XMLRPC, or whatever
Normally (i.e. with normal twisted.web resources), you'd do either a putChild or write a getChild handler. putChild won't work on a WSGI resource, however, nor does it provide a getChild that you could delegate to... so you'll have to do some hacking here.
You create a root resource with a getChild, but you warp the request's paths so that your root controller doesn't "consume" any path fragments. You can use putChild() on the root resource to put "channels" in (or any other root name, such as "RPC"), and only undefined children will be delegated to the WSGI.
class Root( Resource ):
"""Root resource that combines the two sites/entry points"""
WSGI = None
def getChild( self, child, request ):
def render( self, request ):
"""Delegate to the WSGI resource"""
return self.WSGI.render( request )
The WSGI child is "promoted" to the root by being delegated to for both the root render and the lookup of all non-statically-defined root url fragments. Enjoy.
Pingbacks are closed.