[Zope3-checkins] CVS: Zope3/src/zope/app/container - configure.zcml:1.10.14.2 zopecontainer.py:1.15.2.2

Steve Alexander steve@cat-box.net
Thu, 15 May 2003 10:49:58 -0400


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv12712/src/zope/app/container

Modified Files:
      Tag: stevea-decorators-branch
	configure.zcml zopecontainer.py 
Log Message:
More work on Decorators.
Converted existing tests to use decorators instead of ZopeContainerAdapter.


=== Zope3/src/zope/app/container/configure.zcml 1.10.14.1 => 1.10.14.2 ===
--- Zope3/src/zope/app/container/configure.zcml:1.10.14.1	Wed May 14 13:44:10 2003
+++ Zope3/src/zope/app/container/configure.zcml	Thu May 15 10:49:27 2003
@@ -32,8 +32,7 @@
   <decorator
       id="zope.app.container.contextdecorator"
       class="zope.app.container.zopecontainer.ZopeContainerDecorator"
-      names="__getitem__ get __contains__ values items setObject
-             __delitem__ rename"
+      names="__getitem__ get values items setObject __delitem__ rename"
       trusted="trusted">
     <require permission="zope.ManageContent" attributes="rename" />
   </decorator>


=== Zope3/src/zope/app/container/zopecontainer.py 1.15.2.1 => 1.15.2.2 ===
--- Zope3/src/zope/app/container/zopecontainer.py:1.15.2.1	Wed May 14 13:44:10 2003
+++ Zope3/src/zope/app/container/zopecontainer.py	Thu May 15 10:49:27 2003
@@ -33,12 +33,17 @@
      import ObjectRemovedEvent, ObjectModifiedEvent, ObjectAddedEvent
 from zope.interface import implements
 
+__metaclass__ = type
+
 _marker = object()
 
 class ZopeContainerDecorator:
-
     implements(IZopeContainer)
 
+    def __init__(self, inner, outer):
+        self.inner = inner
+        self.outer = outer
+
     def __getitem__(self, key):
         "See IZopeItemContainer"
         value = self.inner[key]
@@ -52,9 +57,9 @@
         else:
             return default
 
-    def __contains__(self, key):
-        '''See interface IReadContainer'''
-        return key in self.inner
+#     def __contains__(self, key):
+#         '''See interface IReadContainer'''
+#         return key in self.inner
 
     def values(self):
         "See IZopeReadContainer"
@@ -104,7 +109,7 @@
         # We explicitly get the object back from the container with
         # container[key], because some kinds of container may choose
         # to store a different object than the exact one we added.
-        object = ContextWrapper(container[key], outer, name=key)
+        object = ContextWrapper(inner[key], outer, name=key)
         publish(outer, ObjectAddedEvent(object))
 
         # Call the after add hook, if necessary
@@ -118,21 +123,22 @@
     def __delitem__(self, key):
         "See IZopeWriteContainer"
         outer = self.outer
+        inner = self.inner
 
-        object = container[key]
+        object = inner[key]
         object = ContextWrapper(object, outer, name=key)
 
-        # Call the before delete hook, if necessary
+        # Call the before delete hook, if necessary.
         adapter = queryAdapter(object, IDeleteNotifiable)
         if adapter is not None:
             adapter.beforeDeleteHook(object, outer)
         elif hasattr(object, 'beforeDeleteHook'):
-            # XXX: Ideally, only do this in debug mode.
+            # XXX: Ideally, do this only in debug mode.
             from warnings import warn
             warn('Class %s has beforeDeleteHook but is not'
                  ' IDeleteNotifiable' % object.__class__)
 
-        del self.inner[key]
+        del inner[key]
 
         publish(outer, ObjectRemovedEvent(object))
         publish(outer, ObjectModifiedEvent(outer))