On 18 Jan 2007, at 09:53 , Chris Withers wrote:
Philipp von Weitershausen wrote:
If it is, then which of the following should I use to register a generic adapter for any single object to an interface:

This one.

Given that you can register adapters for any class, whether or not it implements any interface, this doesn't work as it should:

>>> from zope.component import provideAdapter
>>> def adapter(*args): pass

This is your problem. The 'adapter' function is a factory so it's supposed to actually return the value of the adaption. If ITest(1) returns None, then the component architecture thinks adaption has failed. This is a well-known and intended behaviour.

>>> from zope.interface import Interface
>>> class ITest(Interface): pass
>>> provideAdapter(adapter,adapts=(None,),provides=ITest)

>>> ITest(1)
Traceback (most recent call last):
TypeError: ('Could not adapt', 1, <InterfaceClass __main__.ITest>)

>>> class test: pass
>>> ITest(test())
TypeError: ('Could not adapt', <__main__.test instance at ...>, <InterfaceClass __main__.ITest>)

I have no idea what a "generic" adapter is, but the zope.component API docs (== interfaces) are certainly complete in this sense. There are also doctests.

Where can I find the docs and interfaces you mention above? I looked through both zope.interface and zope.component and obviously missed them :-(

Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to