Package pyxmpp :: Module interface

[hide private]

# Module interface

source code

Interface API.

If zope.interface is available this module will be its equivalent, otherwise minimum interface API (partially compatible with zope.interface) will be defined here.

When full ZopeInterfaces API is needed impoer zope.interface instead of this module.

Classes | [hide private]

| Interface
| Attribute Attribute descriptions

Functions | [hide private]

providedBy(...) Get an object's interfaces |

implementedBy(...) Interfaces implemented by a class or factory. |

implements(*interfaces) Declare interfaces implemented by instances of a class |

Variables | [hide private]

| __package__ = ``'``pyxmpp``'``

Function Details | [hide private]

### implementedBy(...)

Interfaces implemented by a class or factory. Raises TypeError if argument is neither a class nor a callable.

### implements(*interfaces)

Declare interfaces implemented by instances of a class

This function is called in a class definition.

The arguments are one or more interfaces or interface specifications (IDeclaration objects).

The interfaces given (including the interfaces in the specifications) are added to any interfaces previously declared.

Previous declarations include declarations for base classes unless implementsOnly was used.

This function is provided for convenience. It provides a more convenient way to call classImplements. For example:

    implements(I1)

is equivalent to calling:

    classImplements(C, I1)

after the class has been created.

Consider the following example:

    >>> from zope.interface import Interface
    >>> class IA1(Interface): pass
    ...
    >>> class IA2(Interface): pass
    ...
    >>> class IB(Interface): pass
    ...
    >>> class IC(Interface): pass
    ...
    >>> class A(object): implements(IA1, IA2)
    ...
    >>> class B(object): implements(IB)
    ...

    >>> class C(A, B):
    ...    implements(IC)

    >>> ob = C()
    >>> int(IA1 in providedBy(ob))
    1
    >>> int(IA2 in providedBy(ob))
    1
    >>> int(IB in providedBy(ob))
    1
    >>> int(IC in providedBy(ob))
    1

Instances of `C` implement `I1`, `I2`, and whatever interfaces instances of `A` and `B` implement.