directlyProvides(object, *interfaces)
Declare interfaces declared directly for an object
The arguments after the object are one or more interfaces or interface specifications (IDeclaration objects).
The interfaces given (including the interfaces in the specifications) replace interfaces previously declared for the object.
Consider the following example:
>>> from zope.interface import Interface >>> class I1(Interface): pass ... >>> class I2(Interface): pass ... >>> 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() >>> directlyProvides(ob, I1, I2) >>> int(I1 in providedBy(ob)) 1 >>> int(I2 in providedBy(ob)) 1 >>> int(IA1 in providedBy(ob)) 1 >>> int(IA2 in providedBy(ob)) 1 >>> int(IB in providedBy(ob)) 1 >>> int(IC in providedBy(ob)) 1
The object, ob provides I1, I2, and whatever interfaces instances have been declared for instances of C.
To remove directly provided interfaces, use directlyProvidedBy and subtract the unwanted interfaces. For example:
>>> directlyProvides(ob, directlyProvidedBy(ob)-I2) >>> int(I1 in providedBy(ob)) 1 >>> int(I2 in providedBy(ob)) 0
removes I2 from the interfaces directly provided by ob. The object, ob no longer directly provides I2, although it might still provide I2 if it's class implements I2.
To add directly provided interfaces, use directlyProvidedBy and include additional interfaces. For example:
>>> int(I2 in providedBy(ob)) 0 >>> directlyProvides(ob, directlyProvidedBy(ob), I2)
adds I2 to the interfaces directly provided by ob:
>>> int(I2 in providedBy(ob)) 1