[Twisted-web] Why not "remember" the clientHandle at the start of rendering?

Mike C. Fletcher mcfletch at rogers.com
Thu Sep 15 16:59:23 MDT 2005


When rendering a LivePage, we have a method render_liveglue which, as a 
hidden side-effect, creates a client handle in self.clientFactory (then 
promptly forgets about it, making it difficult to reference).  Thing is, 
having that clientHandle available throughout the rendering process 
would be quite convenient, so why not create it in the renderHTTP method 
and remember it there for use by anything that's wanting access to it?

    def renderHTTP(self, ctx):
        """Override to store the client-handle in the main page context"""
        handle = self.clientFactory.newClientHandle(
            self, self.refreshInterval,self.targetTimeoutCount
        )
        ctx.remember( handle, IClientHandle )
        return super( LivePage, self ).renderHTTP( ctx )
    def render_liveglue(self, ctx, data):
        """Override to use already-created client handle (from 
renderHTTP)"""
        if not self.cacheable:
            handle = IClientHandle( ctx )
            handleId = "'", handle.handleId, "'"
        else:
            handleId = 'null'
        return [
            tags.script(type="text/javascript")[
                "var nevow_clientHandleId = ", handleId ,";"],
            tags.script(type="text/javascript",
                        src=url.here.child('nevow_glue.js'))
        ]

Noticed this as I was implementing the new handler implementation posted 
about a little while ago (it now works, incidentally, with a few bumps 
and twists).

Have fun,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the Twisted-web mailing list