[Twisted-Python] session

Glyph Lefkowitz glyph at twistedmatrix.com
Sun Feb 16 10:57:10 EST 2003

On Sunday, February 16, 2003, at 09:06 AM, Thomas Weholt wrote:

>> No -- you want to use .rpys (.rpys can be used for XML-RPC resources
>> too, of course). William made some nice changes to that example, but
>> changing it to instantiate its own server.Site was a bad one.

> I cannot get the grip on how to use childs and leafs in Twisted. I 
> think my code should be written to use that somehow. The reason I need 
> this is because I need to have a perstistent object, containing 
> compiled templates ( using simple TAL/ES ), users-information and a 
> dict of what I've called webapps, similar to the rpys I guess, in 
> memory. I think that can work with some of the sample code I've seen. 
> But I want to pass more parameters to the rpy-file that will produce 
> the content, not just call it's render method.

You want to use twisted.web.woven.tapestry: however, it's not entirely 
ready.  At last I knew of it, this module was going to be deprecated 
and functionality was going to be rolled back into Controller.  At any 
rate, reading the code there should give you some ideas.

Nothing horribly confusing is going to happen to it though.  You will 
probably have to spend 30 minutes renaming some classes when we polish 
and finalize it.

As to the theory:

An RPY is a file that can generate a resource.  It is NOT suggested, in 
an application, to have multiple related resources in different .rpy's. 
  They are conceptually related objects, which you can aggregate by 
using request.putChild and overriding request.getChild.

What you want to do is to create a top-level "site" resource, (not a 
server.Site) and then handle getChild there, returning other Resource 
instances that you can dynamically create, cache, or load from your own 

As far as "leafs" -- in Twisted Web, isLeaf is just a flag that says 
"stop calling getChild here, please".  There's nothing really special 
about it.

A simple example:

	http://asdf.com/foo/bar/baz => root.getChild("foo", 
...).getChild("bar", ...).getChild("baz", ...).render(...)

What happens at each step of that path is pretty much up to you ;).

More information about the Twisted-Python mailing list