[Twisted-web] Livepage, ClientHandle and context

Donovan Preston dp at ulaluma.com
Mon May 30 17:31:33 MDT 2005

On May 30, 2005, at 2:17 PM, Thomas HERVE wrote:

> I've just started to use nevow i18n and I'm pretty happy with it,  
> it works very
> well and the automatic detection of browser language is invisible.
> But my app uses livepage a lot, and I began to face problems when  
> trying to
> translate strings in "dynamic renderers". After some  
> investigations, I found my
> problem : i18n uses the i18nconfig saved in context to translate  
> strings,  but
> livepage.ClientHandle makes a new "fake" context for each calls via  
> the
> livepage.flt function.
> I resolved my problem by creating my ClientHandle and  
> ClientHandleFactory
> implementations, the ClientHandle saving the context at its  
> creation (pretty
> easy, but I would have found it cleaner if clientHandleFactory was  
> a class
> variable of LivePage, Input and Output, and not a module global).  
> Thus, the
> i18nconfig remains in context.
> My question is : is this choice good, or is there a good reason for  
> ClientHandle
> not to keep track of the context ? If not, wouldn't it be better to  
> save context
> in ClientHandle (it would useful for others things, getting session  
> for example)
> ?

You should take a look at the branches/dp/livepage-completion- 
notification-3 branch. It includes a lot of refactoring to livepage,  
one of which causes all of the livepage apis to take a  
JavascriptContext object instead of a ClientHandle. To use the  
ClientHandle, you'll have to get it out of the context, like you  
would other objects: IClientHandle(ctx).

This context is hooked up to the context chain from the outputConduit  
or inputConduit HTTP request, so it should be much more useful to  
you. For example, render_ methods should work properly because  
nevow'll be able to find the IRendererFactory (your Page instance,  

This branch is not yet fully backwards compatible with the previous  
livepage API. sendScript, call, set, and append are not present as  
methods of ClientHandle. Instead, there is a single ClientHandle.send  
method which takes any stan which can be rendered down to javascript.  
For example, IClientHandle(ctx).send(js("any javascript here")) will  
work, as will client.send(livepage.set('foo', 'bar')). I will  
probably add the ClientHandle convenience APIs back soon. They will  
just call send with the appropriate "stan for javascript" object.

In this branch, input handlers can also return javascript which will  
be executed as the response to the input event.

I encourage anyone who is interested in livepage to take a look at  
this branch to see where it is going. Take a look at the examples to  
see what has changed, read the code, and experiment with it. Ask  
questions if you have any. I'll be trying to merge this branch into  
the mainline (after adding some backwards compatibility) in the next  

I'll also be adding some LivePage docs. I think the API will settle  
down after this last round of changes.


More information about the Twisted-web mailing list