[Zope] Five: Adapter registry not working?
Peter Sabaini
peter at sabaini.at
Wed May 30 09:06:31 EDT 2007
Hi list,
I am clearly doing something wrong here.
I try to use an Adapter from zope.app.session with an HTTPRequest object, but
the Adapterregistry doesnt quite cooperate.
Specifically, I try to adapt a HTTPRequest object to
zope.app.session.interfaces.IClientId via the Adapter
zope.app.session.session.ClientId
A short demo:
% ./zopectl debug
[ ... ]
Import stuff:
>>> from ZPublisher.HTTPRequest import *
>>> from StringIO import StringIO
>>> from zope.app.session.session import ClientId
>>> from zope.app.session.interfaces import IClientId
>>> from zope import component
>>> from zope.interface import *
Create ourselves a faux request object:
>>> env = {'SERVER_NAME': '', 'SERVER_PORT' : ''}
>>> request = HTTPRequest(StringIO(), env, None)
ClientId implements IClientId:
>>> list(implementedBy(ClientId))
[<InterfaceClass zope.app.session.interfaces.IClientId>]
It seems ClientId is an Adapter for IRequest:
>>> component.adaptedBy(ClientId)
(<InterfaceClass zope.publisher.interfaces.IRequest>,)
request implements IBrowserRequest, which is a subclass of IRequest:
>>> list(providedBy(request))
[<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>]
>>> issubclass(list(providedBy(request))[0], component.adaptedBy(ClientId)
[0])
True
...so I'd expect to get ClientId as an Adapter for IClientId(request), but I
dont:
>>> IClientId(request)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: ('Could not adapt', <HTTPRequest, URL=http://:>,
<InterfaceClass zope.app.session.interfaces.IClientId>)
Shouldnt this work? Obviously I am missing something here.
This is on Zope 2.10.2 with the built-in Five, and Python 2.4.4
Any help greatly appreciated!
- peter.
More information about the Zope
mailing list