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

Justin Johnson justinjohnson at fastmail.fm
Thu Oct 2 08:30:39 MDT 2003


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.

-----
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()
Locals
self    
ratcontrol.web.pages.MenuPage instance @ 0xc2e760
<ratcontrol.web.pages.MenuPage instance at 0x00C2E760>
request 
twisted.web.server.Request instance @ 0xb9d1e8 <GET / HTTP/1.1>
Globals
webinterfaces   <module 'ratcontrol.web.webinterfaces' from
'C:\svn\RatControl\ratcontrol\web\webinterfaces.pyc'>
C:\Python23\Lib\site-packages\twisted\python\components.py, line 77 in
__call__
75
76    if adapter is _Nothing:
77      raise CannotAdapt("%s cannot be adapted to %s." %
78               (adaptable, self))
Locals
adaptable       
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'>
Globals
_Nothing        <class twisted.python.components._Nothing at 0x008EEED0>
CannotAdapt     <class twisted.python.components.CannotAdapt at
0x008EEF30>

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

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.

Thanks.
-Justin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pages.py
Type: application/unknown
Size: 2722 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20031002/18185caf/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: session.py
Type: application/unknown
Size: 2428 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20031002/18185caf/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: webinterfaces.py
Type: application/unknown
Size: 2776 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20031002/18185caf/attachment-0008.bin>


More information about the Twisted-Python mailing list