[Twisted-web] resource constructor called on every request

Remi Cool mailinglists at smartology.nl
Thu Nov 24 01:00:45 MST 2005


Hello,

I don't know if this is a 'normal' twisted/nevow operation procedure,
but my base resources' __init__ is called on every request.

Since a putChild for XMLRPC is setup in this __init__ (which includes a
lot of code), I'm worried about execess overhead. Is there a way to
include the XMLRPC section in a way that it get's initialized only once?
I need the XMLRPC functionality on the same port as the HTTP(S) for
firewall reasons.

Something else ... in locateChild ->

if segments[0] == '':
    # If the server is looking for the root page segments will be ('',)
    # then renderHTTP will be called on self

When I return self, () a max recursion error is the result ... what
should I return here?


-- CODE --

class httpResource(rend.Page):
   
    addSlash = True
   
    def __init__(self, service):
        rend.Page.__init__(self)
        self.service = service
        self.putChild('RPC2', protocols.xmlrpc(self.service))
          
        rt = static.File("www")
        rt.ignoreExt(".rpy")
        rt.processors = {'.rpy': script.ResourceScript, '.php': phpScript}
        rt.indexNames.append('index.php')
        self.putChild('www', rt)

    def locateChild(self, ctx, segments):
        """"""
        if segments[0] == '':
            # If the server is looking for the root page segments will
be ('',)
            # then renderHTTP will be called on self
            return None, ()
        elif segments[0] in ctx.tag.children.keys():
            return ctx.tag.children[segments[0]], segments[1:]
        else:
            return None, ()
       
    def renderHTTP(self, ctx):
        """"""
        if self == ctx:
            return "<html><body>renderHTTP: ROOT</body></html>"
        return ctx.tag
       
components.registerAdapter(httpResource, IowwService, inevow.IResource)




More information about the Twisted-web mailing list