classProvides(*interfaces)
Declare interfaces provided directly by a class
This function is called in a class definition.
The arguments are one or more interfaces or interface specifications (IDeclaration objects).
The given interfaces (including the interfaces in the specifications) are used to create the class's direct-object interface specification. An error will be raised if the module class has an direct interface specification. In other words, it is an error to call this function more than once in a class definition.
Note that the given interfaces have nothing to do with the interfaces implemented by instances of the class.
This function is provided for convenience. It provides a more convenient way to call directlyProvides for a class. For example:
classProvides(I1)
is equivalent to calling:
directlyProvides(theclass, I1)
after the class has been created.
For example:
>>> from zope.interface import Interface >>> class IFoo(Interface): pass ... >>> class IFooFactory(Interface): pass ... >>> class C(object): ... implements(IFoo) ... classProvides(IFooFactory) >>> [i.getName() for i in C.__providedBy__] ['IFooFactory'] >>> [i.getName() for i in C().__providedBy__] ['IFoo']
if equivalent to:
>>> from zope.interface import Interface >>> class IFoo(Interface): pass ... >>> class IFooFactory(Interface): pass ... >>> class C(object): ... implements(IFoo) >>> directlyProvides(C, IFooFactory) >>> [i.getName() for i in C.__providedBy__] ['IFooFactory'] >>> [i.getName() for i in C().__providedBy__] ['IFoo']
If classProvides is called outside of a class definition, it fails.
>>> classProvides(IFooFactory) Traceback (most recent call last): ... TypeError: classProvides can be used only from a class definition.