[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/container/ Fixed a bug in ContainedProxy that prevented dclaring interfaces for

Jim Fulton jim at zope.com
Tue Aug 17 09:46:50 EDT 2004


Log message for revision 27166:
  Fixed a bug in ContainedProxy that prevented dclaring interfaces for
  proxied instances.
  


Changed:
  U   Zope3/trunk/src/zope/app/container/contained.py
  U   Zope3/trunk/src/zope/app/container/tests/test_contained.py


-=-
Modified: Zope3/trunk/src/zope/app/container/contained.py
===================================================================
--- Zope3/trunk/src/zope/app/container/contained.py	2004-08-17 11:20:31 UTC (rev 27165)
+++ Zope3/trunk/src/zope/app/container/contained.py	2004-08-17 13:46:50 UTC (rev 27166)
@@ -21,8 +21,7 @@
 from zope.exceptions import DuplicationError
 from zope.security.checker import selectChecker, CombinedChecker
 
-import zope.interface
-from zope.interface.declarations import ObjectSpecificationDescriptor
+import zope.interface.declarations
 from zope.interface.declarations import getObjectSpecification
 from zope.interface.declarations import ObjectSpecification
 from zope.interface import providedBy
@@ -736,7 +735,8 @@
         return n
 
 
-class DecoratorSpecificationDescriptor(ObjectSpecificationDescriptor):
+class DecoratorSpecificationDescriptor(
+    zope.interface.declarations.ObjectSpecificationDescriptor):
     """Support for interface declarations on decorators
 
     >>> from zope.interface import *
@@ -808,7 +808,16 @@
             else:
                 return CombinedChecker(wrapper_checker, checker)
 
+class ContainedProxyClassProvides(zope.interface.declarations.ClassProvides):
 
+    def __set__(self, inst, value):
+        inst = getProxiedObject(inst)
+        inst.__provides__ = value
+
+    def __delete__(self, inst):
+        inst = getProxiedObject(inst)
+        del inst.__provides__
+
 class ContainedProxy(ContainedProxyBase):
 
     __safe_for_unpickling__ = True
@@ -819,5 +828,5 @@
 
     __Security_checker__ = DecoratedSecurityCheckerDescriptor()
 
+ContainedProxy.__provides__ = ContainedProxyClassProvides(ContainedProxy, type)
 
-

Modified: Zope3/trunk/src/zope/app/container/tests/test_contained.py
===================================================================
--- Zope3/trunk/src/zope/app/container/tests/test_contained.py	2004-08-17 11:20:31 UTC (rev 27165)
+++ Zope3/trunk/src/zope/app/container/tests/test_contained.py	2004-08-17 13:46:50 UTC (rev 27166)
@@ -13,14 +13,17 @@
 ##############################################################################
 import unittest
 import gc
-from zope.testing.doctestunit import DocTestSuite
-from zope.app.tests.placelesssetup import setUp, tearDown
-from zope.app.container.contained import ContainedProxy
 from ZODB.DemoStorage import DemoStorage
 from ZODB.DB import DB
 from transaction import get_transaction
 from persistent import Persistent
 
+import zope.interface
+from zope.testing.doctestunit import DocTestSuite
+
+from zope.app.tests.placelesssetup import setUp, tearDown
+from zope.app.container.contained import ContainedProxy
+
 class MyOb(Persistent):
     pass
 
@@ -79,7 +82,64 @@
 
     >>> db.close()
     """
+
+def test_declarations_on_ContainedProxy():
+    """
+
+    ..Ignoe whitespace differences
+      >>> doctest: +NORMALIZE_WHITESPACE
     
+    It is possible to make declarations on ContainedProxy objects.
+
+      >>> class I1(zope.interface.Interface):
+      ...     pass
+      >>> class C(object):
+      ...     zope.interface.implements(I1)
+
+      >>> c = C()
+      >>> p = ContainedProxy(c)
+
+    ContainedProxy provides no interfaces on it's own:
+      
+      >>> tuple(zope.interface.providedBy(ContainedProxy))
+      ()
+
+    It implements IContained and IPersistent:
+      
+      >>> tuple(zope.interface.implementedBy(ContainedProxy))
+      (<InterfaceClass zope.app.container.interfaces.IContained>,
+       <InterfaceClass persistent.interfaces.IPersistent>)
+
+    A proxied object has IContainer, in addition to what the unproxied
+    object has:
+
+      >>> tuple(zope.interface.providedBy(p))
+      (<InterfaceClass zope.app.container.tests.test_contained.I1>,
+       <InterfaceClass zope.app.container.interfaces.IContained>,
+       <InterfaceClass persistent.interfaces.IPersistent>)
+
+      >>> class I2(zope.interface.Interface):
+      ...     pass
+      >>> zope.interface.directlyProvides(c, I2)
+      >>> tuple(zope.interface.providedBy(p))
+      (<InterfaceClass zope.app.container.tests.test_contained.I2>,
+       <InterfaceClass zope.app.container.tests.test_contained.I1>,
+       <InterfaceClass zope.app.container.interfaces.IContained>,
+       <InterfaceClass persistent.interfaces.IPersistent>)
+
+    We can declare interfaces through the proxy:
+
+      >>> class I3(zope.interface.Interface):
+      ...     pass
+      >>> zope.interface.directlyProvides(p, I3)
+      >>> tuple(zope.interface.providedBy(p))
+      (<InterfaceClass zope.app.container.tests.test_contained.I3>,
+       <InterfaceClass zope.app.container.tests.test_contained.I1>,
+       <InterfaceClass zope.app.container.interfaces.IContained>,
+       <InterfaceClass persistent.interfaces.IPersistent>)
+
+    """
+    
 def test_basic_persistent_w_persistent_proxied():
     """
 



More information about the Zope3-Checkins mailing list