[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/container/con Added a ISublocations adapter for containers.

Jim Fulton jim at zope.com
Sat May 29 09:20:46 EDT 2004


Log message for revision 25125:
Added a ISublocations adapter for containers.



-=-
Modified: Zope3/trunk/src/zope/app/container/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/container/configure.zcml	2004-05-29 12:39:08 UTC (rev 25124)
+++ Zope3/trunk/src/zope/app/container/configure.zcml	2004-05-29 13:20:46 UTC (rev 25125)
@@ -56,6 +56,11 @@
       Handler dispatches moved events to sublocations of the original object.
   </subscriber>
 
+  <adapter
+      provides="zope.app.location.interfaces.ISublocations"
+      for="zope.app.container.interfaces.IReadContainer"
+      factory=".contained.ContainerSublocations"
+      />
 
   <content class=".constraints.ItemTypePrecondition">
     <allow interface=".constraints.IItemTypePrecondition" />

Modified: Zope3/trunk/src/zope/app/container/contained.py
===================================================================
--- Zope3/trunk/src/zope/app/container/contained.py	2004-05-29 12:39:08 UTC (rev 25124)
+++ Zope3/trunk/src/zope/app/container/contained.py	2004-05-29 13:20:46 UTC (rev 25125)
@@ -31,7 +31,7 @@
 from zope.app.event.objectevent import ObjectEvent, modified
 from zope.event import notify
 from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.container.interfaces import IContained
+from zope.app.container.interfaces import IContained, IReadContainer
 from zope.app.container.interfaces import INameChooser
 from zope.app.container.interfaces import IObjectAddedEvent
 from zope.app.container.interfaces import IObjectMovedEvent
@@ -176,9 +176,38 @@
         for sub in subs.sublocations():
             for ignored in zapi.subscribers((sub, event), None):
                 pass # They do work in the adapter fetch
-    
 
+class ContainerSublocations(object):
+    """Get the sublocations for a container
 
+       Obviously, this is the container values:
+
+         >>> class MyContainer:
+         ...     def __init__(self, **data):
+         ...         self.data = data
+         ...     def __iter__(self):
+         ...         return iter(self.data)
+         ...     def __getitem__(self, key):
+         ...         return self.data[key]
+
+         >>> container = MyContainer(x=1, y=2, z=42)
+         >>> adapter = ContainerSublocations(container)
+         >>> sublocations = list(adapter.sublocations())
+         >>> sublocations.sort()
+         >>> sublocations
+         [1, 2, 42]
+      
+       """
+
+    def __init__(self, container):
+        self.container = container
+
+    def sublocations(self):
+        container = self.container
+        for key in container:
+            yield container[key]
+
+
 def containedEvent(object, container, name=None):
     """Establish the containment of the object in the container
 




More information about the Zope3-Checkins mailing list