[Zope3-dev] adaptation based on class rather than interface

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Nov 9 10:30:34 EST 2006


On Thursday 09 November 2006 10:02, Chris Withers wrote:
> ...will work, right?

>>> import zope.component
>>> class A(object):
...   pass
...
>>> class B(A):
...   pass
...
>>> import zope.interface
>>> class ISomething(zope.interface.Interface):
...   pass
...
>>> class BToSomething(object):
...   def __init__(self, context):
...     pass
...
>>> zope.component.provideAdapter(BToSomething, 
[zope.interface.implementedBy(B)], ISomething)
>>> ISomething(b)
<__main__.BToSomething object at 0xb7a4fa4c>
>>> from zope.component.globalregistry import base
>>> base.__init__('base')
>>> ISomething(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: ('Could not adapt', <__main__.B object at 0xb7a4f96c>, 
<InterfaceClass __main__.ISomething>)
>>> zope.component.provideAdapter(BToSomething, 
[zope.interface.implementedBy(A)], ISomething)
>>> ISomething(b)
<__main__.BToSomething object at 0xb7a4f9ac>
>>>   

-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-dev mailing list