[Zope3-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.11
Jim Fulton
jim@zope.com
Mon, 2 Jun 2003 07:07:58 -0400
Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv20381/src/zope/interface
Modified Files:
declarations.py
Log Message:
Added __nonzero__ implementation and test for interface specificationss,
=== Zope3/src/zope/interface/declarations.py 1.10 => 1.11 ===
--- Zope3/src/zope/interface/declarations.py:1.10 Sun Jun 1 18:26:51 2003
+++ Zope3/src/zope/interface/declarations.py Mon Jun 2 07:07:58 2003
@@ -231,6 +231,32 @@
self.provides = provides
self.cls = cls
+ def __nonzero__(self):
+ """
+ >>> from zope.interface import Interface
+ >>> class I1(Interface):
+ ... pass
+ >>> class I2(Interface):
+ ... pass
+ >>> class C:
+ ... implements(I1)
+ >>> c = C()
+ >>> int(bool(providedBy(c)))
+ 1
+ >>> directlyProvides(c, I2)
+ >>> int(bool(providedBy(c)))
+ 1
+ >>> class C:
+ ... pass
+ >>> c = C()
+ >>> int(bool(providedBy(c)))
+ 0
+ >>> directlyProvides(c, I2)
+ >>> int(bool(providedBy(c)))
+ 1
+ """
+ return bool(self.__signature__)
+
def __signature__(self):
provides = self.provides
@@ -416,6 +442,21 @@
self.set = set
self._computeSignature(iro)
+
+ def __nonzero__(self):
+ """Test whether there are any interfaces in a specification.
+
+ >>> from zope.interface import Interface
+ >>> class I1(Interface): pass
+ ...
+ >>> spec = InterfaceSpecification(I1)
+ >>> int(bool(spec))
+ 1
+ >>> spec = InterfaceSpecification()
+ >>> int(bool(spec))
+ 0
+ """
+ return bool(self.interfaces)
def _computeSignature(self, iro):
"""Compute a specification signature