[Twisted-Python] Adapter troubles - Copying Quotient's DivmodSession
dp at twistedmatrix.com
Fri Oct 3 12:15:07 EDT 2003
On Oct 2, 2003, at 10:30 AM, Justin Johnson wrote:
> I've created a class called RatControlSession similar to DivmodSession
> Quotient. I define IRatControlSession and RatControlSession, and I
> register RatControlSession as an adapter from
> to IRatControlSession. However, when I try to do something like...
> prefs = webinterfaces.IRatControlSession(request.getSession())
> I get the following error. This is a cut-n-paste from what appears in
> the browser.
> I'm not sure what I'm doing wrong here. I looked through components.py
> but still don't see what the problem is.
> I've attached webinterfaces.py and session.py, setup similar to
> quotient's respective files. Also attached is pages.py which defines
> wmfactory_action on MenuPage where I try to create an
> from request.getSession().
From looking at the files, it looks like session is not getting
imported anywhere. You would think it wouldn't be a problem since you
are not directly using any of the objects in the module, but unless you
import a module, the code at the top level of that module does not get
executed. Thus the registerAdapter calls are never happening, and when
you go to request an adapter none is registered. Try putting "import
session" at the top of your pages file.
This is a major problem with using components and twisted -- where to
register the adapters. Of course, the implementation of components as
pioneered by Zope 3 uses a non-python file to register adapters (a zcml
file, a form of XML) and twisted should have something similar
(preferably not xml) but currently does not.
More information about the Twisted-Python