Function
zope.component.interface.provideInterface

Signature

provideInterface(id, interface, iface_type=None, info='')

Documentation String

register Interface with global site manager as utility

>>> gsm = zope.component.getGlobalSiteManager()
>>> from zope.interface import Interface
>>> from zope.interface.interfaces import IInterface
>>> from zope.component.tests import ITestType
>>> class I(Interface):
...     pass
>>> IInterface.providedBy(I)
True
>>> ITestType.providedBy(I)
False
>>> interfaces = gsm.getUtilitiesFor(ITestType)
>>> list(interfaces)
[]

# provide first interface type >>> provideInterface('', I, ITestType) >>> ITestType.providedBy(I) True >>> interfaces = list(gsm.getUtilitiesFor(ITestType)) >>> [name for (name, iface) in interfaces] [u'zope.component.interface.I'] >>> [iface.__name__ for (name, iface) in interfaces] ['I']

# provide second interface type >>> class IOtherType(IInterface): ... pass >>> provideInterface('', I, IOtherType)

>>> ITestType.providedBy(I)
True
>>> IOtherType.providedBy(I)
True
>>> interfaces = list(gsm.getUtilitiesFor(ITestType))
>>> [name for (name, iface) in interfaces]
[u'zope.component.interface.I']
>>> interfaces = list(gsm.getUtilitiesFor(IOtherType))
>>> [name for (name, iface) in interfaces]
[u'zope.component.interface.I']
>>> class I1(Interface):
...     pass
>>> provideInterface('', I1)
>>> IInterface.providedBy(I1)
True
>>> ITestType.providedBy(I1)
False
>>> interfaces = list(gsm.getUtilitiesFor(ITestType))
>>> [name for (name, iface) in interfaces]
[u'zope.component.interface.I']
>>> [iface.__name__ for (name, iface) in interfaces]
['I']