[Twisted-web] Re: Context Help

Michael M m.milvo at gmail.com
Mon Sep 12 23:55:31 MDT 2005


Its been pointed out to me that some of my messages have not been
going to the list so I will post a summary of what I have learnt so
far thanks to Tommi.


I was under the impression that with context it would be possible to
remember an interface by doing ctx.remember(data, ISomeInterface) and
then recall this interface anywhere throughout the request.

This does not work as I expected and the reason for this is that
context changes throughout the request and so looses what it has
remembered when it changes.

Example:
def render_cow(self, ctx, data):
    """Context is say WovenContext"""
    ctx.remember('myinfo', ISomeInterface)

def render_dog(self, ctx, data):
    """Context is now PageContext"""
    myinfo = ctx.locate(ISomeInterface)

This will fail because I remembered data when the context was
WovenContext and now the context is PageContext and so it does not
have the data and interface that I remembered.

Now I didn't think that this would be a problem because I thought that
the context stack?? would be searched, i,e PageContext is searched for
ISomeInterface, then maybe WovenContext is searched etc until the
interface is found.

Obviously this is not quite right.

Tommi stated that:
"Nested in template does not mean nested in implementation." and
"remember the thing you want on something that stays on the stack for
the duration you want."

>From this I gather that some interfaces stay on the context stack
longer than others?

So I need to investigate the following.  

1.) How do I find out what interfaces stays on the stack for the
duration of the whole request?

2.) If I remebered say ctx.remember('myinfo', IRequest)...will this
mean I cannot use IRequest to retrieve the request, i.e I will have
overwritten request.

3.) How to I make my own interfaces stay on the stack throughout the request.

Off to read some more nevow code and do some tests and I will post
back to the list the results so hopefully some other users benefit.

Cheers
Michael



More information about the Twisted-web mailing list