Component Adaptation + Open Protocols
= The PyProtocols Package
Importing this module enables experimental support for using Zope X3
Interface objects with the protocols package, by registering
an adapter from Zope X3's InterfaceClass to IOpenProtocol. The
adapter supports the following subset of the declaration API:
- The only adapters supported via Zope APIs are NO_ADAPTER_NEEDED
and DOES_NOT_SUPPORT. By using PyProtocols APIs, you may declare and
use other adapters for Zope interfaces, but Zope itself will not use them, since
the Zope interface API does not directly support adaptation.
- Zope's interface APIs do not conform to protocols package
``shortest path wins'' semantics. Instead, new declarations override older
ones.
- Interface-to-interface adaptation may not work if a class only declares
what it implements using Zope's interface API. That is, if a class declares
that it implements ISomeZopeInterface, and you define an adaptation from
ISomeZopeInterface to ISomeOtherInterface, PyProtocols may not
recognize that the class can be adapted to ISomeOtherInterface.
- Changing the __bases__ of a class that has Zope interfaces
declared for it (either as ``class provides'' or ``instances provide''), may
have unexpected results, because Zope uses inheritance of a single descriptor
to control declarations. In general, it will only work if the class whose
bases are changed, has no declarations of its own.
- You cannot declare an implication relationship from a Zope
Interface, because Zope only supports implication via
inheritance, which is fixed at interface definition time. Therefore, you cannot
create a ``subset'' of a Zope Interface, and subscribing an
IImplicationListener to an adapted Zope Interface
silently does nothing.
- You can, however, declare that a protocols.Interface extends a
Zope Interface. Declaring that a class' instances or that an object
provides the extended interface, will automatically declare that the class'
instances or the object provides the Zope Interface as well. For
example:
[画像:\begin{verbatim}import protocols from zope.somepackage.interfaces import IBase \... ...ass AnImplementation: advise( instancesProvide = [IExtended] ) \end{verbatim}]
The above code should result in Zope recognizing that instances of
AnImplementation provide the Zope IBase interface.
- You cannot extend both a Zope interface and a Twisted interface in the
same protocols.Interface. Although this may not give you any errors,
Twisted and Zope both expect to use an __implements__ attribute to
store information about what interface a class or object provides. But each has
a different interpretation of the contents, and does not expect to find
``foreign'' interfaces contained within. So, until this issue between Zope and
Twisted is resolved, it is not very useful to create interfaces that extend
both Zope and Twisted interfaces.
- Zope does not currently appear to support classes inheriting direct
declarations (e.g.
classProvides). This appears to be a by-design
limitation.
The current implementation of support for Zope X3 interfaces is currently based
on Zope X3 beta 1; it may not work with older releases. Zope X3 requires Python
2.3.4 or better, so even though PyProtocols works with 2.2.2 and up in general,
you will need 2.3.4 to use PyProtocols with Zope X3.
Component Adaptation + Open Protocols
= The PyProtocols Package
Release 1.0a0, documentation updated on October 10, 2004.