[Zope3-checkins]
SVN: Zope3/branches/jim-adapter/src/zope/interface/declarations.py
noLongerProvides functionality.
Philipp von Weitershausen
philikon at philikon.de
Mon Feb 27 14:09:29 EST 2006
Log message for revision 65530:
noLongerProvides functionality.
Changed:
U Zope3/branches/jim-adapter/src/zope/interface/declarations.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/interface/declarations.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/interface/declarations.py 2006-02-27 19:04:09 UTC (rev 65529)
+++ Zope3/branches/jim-adapter/src/zope/interface/declarations.py 2006-02-27 19:09:29 UTC (rev 65530)
@@ -927,6 +927,45 @@
"""
directlyProvides(object, directlyProvidedBy(object), *interfaces)
+def noLongerProvides(object, interface):
+ """
+ This removes a directly provided interface from an object.
+ Consider the following two interfaces:
+
+ >>> from zope.interface import Interface
+ >>> class I1(Interface): pass
+ ...
+ >>> class I2(Interface): pass
+ ...
+
+ ``I1`` is provided through the class, ``I2`` is directly provided
+ by the object:
+
+ >>> class C(object):
+ ... implements(I1)
+ >>> c = C()
+ >>> alsoProvides(c, I2)
+ >>> I2.providedBy(c)
+ True
+
+ Remove I2 from c again:
+
+ >>> noLongerProvides(c, I2)
+ >>> I2.providedBy(c)
+ False
+
+ Removing an interface that is provided through the class is not possible:
+
+ >>> noLongerProvides(c, I1)
+ Traceback (most recent call last):
+ ...
+ ValueError: Can only remove directly provided interfaces.
+
+ """
+ directlyProvides(object, directlyProvidedBy(object)-interface)
+ if interface.providedBy(object):
+ raise ValueError("Can only remove directly provided interfaces.")
+
class ClassProvidesBasePy(object):
def __get__(self, inst, cls):
More information about the Zope3-Checkins
mailing list