-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Sabaini wrote:
> 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!

You have verified that 'ClientID' is a suitable candidate for adapting
'IRequest' to 'IClientID', but not that it has been actually registered
as the factory for that adaptaion.

Does adding the following help?

  >>> from zope.component import provideAdapter
  >>> provideAdapter(ClientID)

Also, at the point where the lookup fails, you can try:

  >>> import pdb; pdb.pm()

and be in a "postmortem" traceback of the failed component tookup.


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGXZTF+gerLs4ltQ4RAvLzAJ0UR0/wFghBJK0YcgtGJjdodTBUzwCfdBG/
J0+AFzw3+yGrOgjSQVpzkyw=
=xa7i
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to