[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/container/ Merged from trunk:

Jim Fulton jim at zope.com
Mon Aug 23 19:50:00 EDT 2004


Log message for revision 27238:
  Merged from trunk:
  
    r27166 | jim | 2004-08-17 09:46:50 -0400 (Tue, 17 Aug 2004) | 3 lines
  
  Fixed a bug in ContainedProxy that prevented dclaring interfaces for
  proxied instances.
  
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/container/tests/test_contained.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py	2004-08-23 23:42:11 UTC (rev 27237)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py	2004-08-23 23:50:00 UTC (rev 27238)
@@ -19,8 +19,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
@@ -733,7 +732,8 @@
         return n
 
 
-class DecoratorSpecificationDescriptor(ObjectSpecificationDescriptor):
+class DecoratorSpecificationDescriptor(
+    zope.interface.declarations.ObjectSpecificationDescriptor):
     """Support for interface declarations on decorators
 
     >>> from zope.interface import *
@@ -805,7 +805,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
@@ -816,5 +825,5 @@
 
     __Security_checker__ = DecoratedSecurityCheckerDescriptor()
 
+ContainedProxy.__provides__ = ContainedProxyClassProvides(ContainedProxy, type)
 
-

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/container/tests/test_contained.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/container/tests/test_contained.py	2004-08-23 23:42:11 UTC (rev 27237)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/container/tests/test_contained.py	2004-08-23 23:50:00 UTC (rev 27238)
@@ -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