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 

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)

...so I'd expect to get ClientId as an Adapter for IClientId(request), but I 

    >>> 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.
Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to