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

Justin Johnson justinjohnson at fastmail.fm
Thu Oct 2 10:30:39 EDT 2003


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.

C:\svn\RatControl\ratcontrol\web\pages.py, line 14 in wmfactory_action
12  def wmfactory_action(self, request):
13    #prefs = request.getSession(webinterfaces.IRatControlSession)
14    prefs = webinterfaces.IRatControlSession(request.getSession())
15    #prefs = request.getSession()
ratcontrol.web.pages.MenuPage instance @ 0xc2e760
<ratcontrol.web.pages.MenuPage instance at 0x00C2E760>
twisted.web.server.Request instance @ 0xb9d1e8 <GET / HTTP/1.1>
webinterfaces   <module 'ratcontrol.web.webinterfaces' from
C:\Python23\Lib\site-packages\twisted\python\components.py, line 77 in
76    if adapter is _Nothing:
77      raise CannotAdapt("%s cannot be adapted to %s." %
78               (adaptable, self))
twisted.web.server.Session instance @ 0xbea710
<twisted.web.server.Session instance at 0x00BEA710>
adapter <class twisted.python.components._Nothing at 0x008EEED0>
self    <class 'ratcontrol.web.webinterfaces.IRatControlSession'>
_Nothing        <class twisted.python.components._Nothing at 0x008EEED0>
CannotAdapt     <class twisted.python.components.CannotAdapt at

twisted.python.components.CannotAdapt: <twisted.web.server.Session
instance at 0x00BEA710> cannot be adapted to <class

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().

Any help you can provide is greatly appreciated.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pages.py
Type: application/unknown
Size: 2722 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031002/18185caf/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: session.py
Type: application/unknown
Size: 2428 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031002/18185caf/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: webinterfaces.py
Type: application/unknown
Size: 2776 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031002/18185caf/attachment-0002.bin 

More information about the Twisted-Python mailing list