[Twisted-Python] Adapter for a class, not for an instance
andrew-twisted at puzzling.org
Wed Aug 22 02:28:11 EDT 2007
This is really a Zope question, not Twisted question. You'll probably get
better answers by asking on a Zope mailing list. Anyway...
Vincent Bernat wrote:
> Here is what I do.
> from zope.interface import Interface, implements
> from twisted.python.components import registerAdapter, Adapter
> class DummyAdapter(Adapter):
> class IDummy1(Interface):
> class IDummy2(Interface):
> class Dummy1(object):
> registerAdapter(DummyAdapter, IDummy1, IDummy2)
> IDummy2(Dummy1()) # Works
> IDummy2(Dummy1) # Don't works
> If I use registerAdapter(DummyAdapter, type, IDummy2), this works, but I
> lose a lot of functionality (I may want to adapt other interfaces than
Read the zope.interface documentation, particularly the distinction between
providing an interface and implmenting an interface. If you want
IDummy2(Dummy1) to work, you need to declare Dummy1 as:
However you almost certainly do not want that class to also implement(IDummy1).
It would be very unusual for a type and its instances to both provide the same
More information about the Twisted-Python