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
>>> 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 :-(


Simplistix - Content Management, Zope & Python Consulting

Zope3-dev mailing list

Reply via email to