| |
provide |
implement |
| descriptor |
- classProvides
- moduleProvides
|
- implements
- implementsOnly
|
| decorator |
|
- implementer
- implementer_only
|
| imperative |
- directlyProvides
- alsoProvides
- noLongerProvides
|
- classImplements
- classImplementsOnly
|
| predicate |
- providedBy
- directlyProvidedBy
|
|
- "X provides Y" means the object X can act as the interface Y.
- "X implements Y" means an instance of class X can act as the interface Y.
>>> from zope.interface import *
>>> class IFoo(Interface): pass
...
>>> class IBar(Interface): pass
...
>>> class IFooFactory(Interface): pass
...
>>> class C1(object):
... implements(IFoo)
... classProvides(IFooFactory)
...
>>> @implementer(IFoo)
... @provider(IFooFactory)
... class C2(object):
... pass
...
>>> class C3(object):
... pass
...
>>> classImplements(C3, IFoo)
>>> directlyProvides(C3, IFooFactory)
>>> [i.getName() for i in implementedBy(C1)]
['IFoo']
>>> [i.getName() for i in providedBy(C1)]
['IFooFactory']
>>> [i.getName() for i in providedBy(C1())]
['IFoo']
>>> [i.getName() for i in directlyProvidedBy(C1)]
['IFooFactory']
>>> [i.getName() for i in directlyProvidedBy(C1())]
[]
>>> o = C1()
>>> directlyProvides(o, IBar)
>>> [i.getName() for i in providedBy(o)]
['IBar', 'IFoo']
>>> [i.getName() for i in directlyProvidedBy(o)]
['IBar']
>>> from zope.interface.registry import Components
>>> registry = Components()
>>> registry.registerUtility(C1)
>>> registry.registerUtility(o, IBar)
>>> registry.queryUtility(IFooFactory) is C1
True
>>> registry.queryUtility(IBar) is o
True