[Twisted-Python] Adapter troubles - Copying Quotient's DivmodSession

Donovan Preston dp at twistedmatrix.com
Fri Oct 3 12:15:07 EDT 2003

On Oct 2, 2003, at 10:30 AM, Justin Johnson wrote:

> Hi,
> I've created a class called RatControlSession similar to DivmodSession 
> in
> Quotient.  I define IRatControlSession and RatControlSession, and I
> register RatControlSession as an adapter from 
> twisted.web.server.Session
> 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.

<snip exception>

> 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 
> IRatControlSession
> 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 mailing list