Classes and Functions typically used for Customization/Extension

These classes and functions are also available from the top-level protocols package. In contrast to the items already covered, these classes and functions are generally needed only when extending the protocols framework, as opposed to merely using it.

class Protocol
Protocol is a base class that implements the IOpenProtocol interface, supplying internal adapter registries for adapting from other protocols or types/classes. Note that you do not necessarily need to use this class (or any other IOpenProtocol implementation) in your programs. Any object that implements the simpler IProtocol or IAdaptingProtocol interfaces may be used as protocols for the adapt() function. Compliance with the IOpenProtocol interface is only required to use the protocols declaration API. (That is, functions whose names begin with declare or advise.)

To create protocols dynamically, you can create individual Protocol instances, and then use them with the declaration API. You can also subclass Protocol to create your own protocol types. If you override __init__, however, be sure to call Protocol.__init__() in your subclass' __init__ method.

class Variation( baseProtocol [, context=None])
New in version 0.9.1. A Variation is a Protocol that "inherits" adapter declarations from an existing protocol. When you create a Variation, it declares that it is implied by its baseProtocol, and so any adpater suitable for adapting to the base protocol is therefore suitable for the Variation. This allows you to then declare adapters to the variation protocol, without affecting those declared for the base protocol. In this way, you can have a protocol object that represents the use of the base protocol in a particular context. You can optionally specify that context via the context argument, which will then serve as the context attribute of the protocol. For more background on how this works and what it might be used for, see section 1.1.10.

class AbstractBaseMeta( name, bases, dictionary)
New in version 0.9.3. AbstractBaseMeta, a subclass of Protocol and type, is a metaclass used to create new "ABC-style" protocol objects, using class statements. You can use this metaclass directly, but it's generally simpler to just subclass AbstractBase instead. Normally, you will only use AbstractBaseMeta if you need to combine it with another metaclass.

class InterfaceClass( name, bases, dictionary)
InterfaceClass is a subclass of AbstractBaseMeta that implements the convenience adapation API (see section 1.1.3) for its instances. This metaclass is used to create new "pure-style" interfaces (i.e., protocol objects) using class statements. Normally, you will only use InterfaceClass directly if you need to combine it with another metaclass, as it is usually easier just to subclass Interface.

class IBasicSequence( New in version . )
0.9.1 This interface represents the ability to iterate over a container-like object, such as a list or tuple. An IBasicSequence object must have an __iter__() method. By default, only the built-in list and tuple types are declared as having instances providing this interface. If you want to be able to adapt to sequenceOf() protocols from other sequence types, you should declare that their instances support this protocol.

class ProviderMixin
If you have a class with a __conform__ method for its instances, but you also want the instances to support IOpenprovider (so that adviseObject can be used on them), you may want to include this class as one of your class' bases. The default adapters for IOpenprovider can only adapt objects that do not already have a __conform__ method of their own.

So, to support IOpenprovider with a custom __conform__ method, subclass ProviderMixin, and have your __conform__ method invoke the base __conform__ method as a default, using supermeta(). (E.g. return supermeta(MyClass,self).__conform__(protocol).) See below for more on the supermeta() function.

metamethod( func)
Wrap func in a manner analagous to classmethod or staticmethod, but as a metaclass-level method that may be redefined by metaclass instances for their instances. For example, if a metaclass wants to define a __conform__ method for its instances (i.e. classes), and those instances (classes) want to define a __conform__ method for their instances, the metaclass should wrap its __conform__ method with metamethod. Otherwise, the metaclass' __conform__ method will be hidden by the class-level __conform__ defined for the class' instances.

supermeta( typ, ob)
Emulates the Python built-in super() function, but with support for metamethods. If you ordinarily would use super(), but are calling a metamethod, you should use supermeta() instead. This is because Python 2.2 does not support using super with properties (which is effectively what metamethods are).

Note that if you are subclassing ProviderMixin or Protocol, you will need to use supermeta() to call almost any inherited methods, since most of the methods provided are wrapped with metamethod().

declareAdapterForType( protocol, adapter, typ [, depth=1])
Declare that adapter adapts instances of class or type typ to protocol, by adapting protocol to IOpenProtocol and calling its registerImplementation method. If typ is adaptable to IOpenImplementor, its declareClassImplements method is called as well.

declareAdapterForObject( protocol, adapter, ob [, depth=1])
Declare that adapter adapts the object ob to protocol, by adapting protocol to IOpenProtocol and calling its registerObject method. Typically, ob must support IOpenProvider. See section 1.1.6 for details.

declareAdapterForProtocol( protocol, adapter, proto [, depth=1])
Declare that adapter adapts objects that provide protocol proto to protocol, by calling adapt(proto,IOpenProtocol).addImpliedProtocol(protocol,adapter,depth).