[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/ Added
alsoProvides function that *adds* a new provided interface to
an object.
Amos Brocco
amos.brocco at mriyasoftware.com
Thu Oct 14 08:18:54 EDT 2004
Log message for revision 28165:
Added alsoProvides function that *adds* a new provided interface to an object.
Changed:
U Zope3/trunk/src/zope/interface/__init__.py
U Zope3/trunk/src/zope/interface/declarations.py
-=-
Modified: Zope3/trunk/src/zope/interface/__init__.py
===================================================================
--- Zope3/trunk/src/zope/interface/__init__.py 2004-10-14 12:16:31 UTC (rev 28164)
+++ Zope3/trunk/src/zope/interface/__init__.py 2004-10-14 12:18:53 UTC (rev 28165)
@@ -62,6 +62,7 @@
from zope.interface.declarations import providedBy, implementedBy
from zope.interface.declarations import classImplements, classImplementsOnly
from zope.interface.declarations import directlyProvidedBy, directlyProvides
+from zope.interface.declarations import alsoProvides
from zope.interface.declarations import implements, implementsOnly
from zope.interface.declarations import classProvides, moduleProvides
from zope.interface.declarations import Declaration
Modified: Zope3/trunk/src/zope/interface/declarations.py
===================================================================
--- Zope3/trunk/src/zope/interface/declarations.py 2004-10-14 12:16:31 UTC (rev 28164)
+++ Zope3/trunk/src/zope/interface/declarations.py 2004-10-14 12:18:53 UTC (rev 28165)
@@ -846,8 +846,76 @@
object.__provides__ = ClassProvides(object, cls, *interfaces)
else:
object.__provides__ = Provides(cls, *interfaces)
+
+
+def alsoProvides(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) are added to the 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)
+ >>> int(I1 in providedBy(ob))
+ 1
+ >>> int(I2 in providedBy(ob))
+ 0
+ >>> int(IA1 in providedBy(ob))
+ 1
+ >>> int(IA2 in providedBy(ob))
+ 1
+ >>> int(IB in providedBy(ob))
+ 1
+ >>> int(IC in providedBy(ob))
+ 1
+
+ >>> alsoProvides(ob, 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``. Notice that the
+ alsoProvides just extends the provided interfaces.
+ """
+ directlyProvides(object, directlyProvidedBy(object), *interfaces)
+
class ClassProvidesBasePy(object):
def __get__(self, inst, cls):
More information about the Zope3-Checkins
mailing list