[Zope3-Users] Adapter registration problem
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Dec 18 10:30:33 EST 2007
On Tuesday 18 December 2007, Chris Withers wrote:
> Why does the following adapter registration not work?
>
> <adapter
> for=".SomeModule.SomeClass *"
> provides=".interfaces.ISomething"
> factory=".factories.Factory"
> name="something"
> />
>
> >>> from zope.component import getAdapters
> >>> from SomeModule import SomeClass
> >>> from interfaces import ISomething
> >>> getAdapters((SomeClass('test'),object()),ISomething)
>
> []
Mmmh, seems like a directive problem:
>>> import zope.component
>>> class MyClass(object):
... pass
...
>>> class MyFactory(object):
... def __init__(self, klass, obj):
... pass
...
>>> zope.component.provideAdapter(
... MyFactory,
... adapts=(MyClass, None),
...
KeyboardInterrupt
>>> import zope.interface
>>> class ISomething(zope.interface.Interface):
... pass
...
>>> zope.component.provideAdapter(
... MyFactory,
... adapts=(MyClass, None),
... provides=ISomething,
... name='something')
>>> zope.component.getAdapters((MyClass(), object()), ISomething)
<generator object at 0xb7c56d8c>
>>> list(zope.component.getAdapters((MyClass(), object()), ISomething))
[(u'something', <__main__.MyFactory object at 0xb7b4a06c>)]
Regards,
Stephan
--
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
More information about the Zope3-users
mailing list