[Twisted-web] Passing context through/around/across webform
mesozoic at polynode.com
Mon Oct 18 07:52:08 MDT 2004
So I've started to move Payago (formerly Go) towards compatibility with
Nevow 0.3's API changes; the biggest impact has been the ubiquitous context,
and not being able to rely on a Page having self.context.
Previously, I had _many_ TypedInterfaces which did something along the lines
def doSomething(self, arg = Choice(choicesAttribute='choices')):
doSomething = autocallable(doSomething)
__implements__ = ICanDoSomething
## do something involving self.context
choices = property(_get_choices)
Now, with the ubiquitous context changes, self.context doesn't exist. (Makes
you wonder what "ubiquitous" really means.) So there are a couple solutions
that I've thought of:
1. Make annotate.Choice support 'choicesMethod', which would take context as
an argument. This seems very difficult because not only webform, but
Typed.coerce(), would have to be able to retrieve the context. Then we'd
have to support Deferreds, because some crazy person would obviously want
that at some point. ;) I tried to write a patch, and it got ugly.
2. Set self.context whenever Page.locateChild or Page.renderHTTP is called.
This is a lot simpler, but it seems like a hack to me, and I'm not sure
whether this will _always_ work.
What do other people think? Is option #1 easier to implement than I'm
thinking? Is option #2 safer than it seems to me? Is there an option #3 that
I don't see right now?
"Never let your sense of morals prevent you from doing what is right."
-- Salvor Hardin, Isaac Asimov's _Foundation_
More information about the Twisted-web