[z3-checkins] r19022 - in z3/Five/trunk: . tests

efge at codespeak.net efge at codespeak.net
Wed Oct 26 18:55:12 CEST 2005


Author: efge
Date: Wed Oct 26 18:55:12 2005
New Revision: 19022

Modified:
   z3/Five/trunk/configure.zcml
   z3/Five/trunk/event.py
   z3/Five/trunk/event.zcml
   z3/Five/trunk/monkey.py
   z3/Five/trunk/tests/event.txt
Log:
Simplified subscribers, make them work for the more general IItem
instead of ISimpleItem+IObjectManager.

Subscriber ordering is now explicit in a single subscriber, instead of
having several and on the implicit ordering of more general to less
general.

(UserFolder is an IItem and not a ISimpleItem, and has a manage_afterAdd...)



Modified: z3/Five/trunk/configure.zcml
==============================================================================
--- z3/Five/trunk/configure.zcml	(original)
+++ z3/Five/trunk/configure.zcml	Wed Oct 26 18:55:12 2005
@@ -6,6 +6,7 @@
   <include file="interfaces.zcml" />
   <include file="permissions.zcml" />
   <include file="i18n.zcml" />
+  <!-- XXX in Five 1.3, directly include file="event.zcml" -->
   <include package=".site" />
   <include package=".browser" />
   <include package=".form" />

Modified: z3/Five/trunk/event.py
==============================================================================
--- z3/Five/trunk/event.py	(original)
+++ z3/Five/trunk/event.py	Wed Oct 26 18:55:12 2005
@@ -34,6 +34,7 @@
 from zope.app.container.contained import ObjectAddedEvent
 from zope.app.container.contained import ObjectRemovedEvent
 from zope.app.event.objectevent import ObjectCopiedEvent
+from zope.app.container.contained import dispatchToSublocations
 
 from Products.Five.fiveconfigure import isFiveMethod
 
@@ -159,13 +160,52 @@
     def sublocations(self):
         for ob in self.container.objectValues():
             yield ob
+        # XXX also want to provide opaqueItems's values
+
+# The following subscribers should really be defined in ZCML
+# but we don't have enough control over subscriber ordering for
+# that to work exactly right.
+# (Sometimes IItem comes before IObjectManager, sometimes after,
+# depending on some of Zope's classes.)
+# This code can be simplified when Zope is completely rid of
+# manage_afterAdd & co, then IItem wouldn't be relevant anymore and we
+# could have a simple subscriber for IObjectManager that directly calls
+# dispatchToSublocations.
+
+def dispatchObjectWillBeMovedEvent(ob, event):
+    """Multi-subscriber for IItem + IObjectWillBeMovedEvent.
+    """
+    # First, dispatch to sublocations
+    if IObjectManager.providedBy(ob):
+        dispatchToSublocations(ob, event)
+    # Next, do the manage_beforeDelete dance
+    if hasDeprecatedMethods(ob):
+        callManageBeforeDelete(ob, event)
+
+def dispatchObjectMovedEvent(ob, event):
+    """Multi-subscriber for IItem + IObjectMovedEvent.
+    """
+    # First, do the manage_afterAdd dance
+    if hasDeprecatedMethods(ob):
+        callManageAfterAdd(ob, event)
+    # Next, dispatch to sublocations
+    if IObjectManager.providedBy(ob):
+        dispatchToSublocations(ob, event)
+
+def dispatchFiveObjectClonedEvent(ob, event):
+    """Multi-subscriber for IItem + IFiveObjectClonedEvent.
+    """
+    # First, do the manage_afterClone dance
+    if hasDeprecatedMethods(ob):
+        callManageAfterClone(ob, event)
+    # Next, dispatch to sublocations
+    if IObjectManager.providedBy(ob):
+        dispatchToSublocations(ob, event)
+
 
 def callManageAfterAdd(ob, event):
     """Compatibility subscriber for manage_afterAdd.
     """
-    # used for ISimpleItem/IObjectManager, IObjectMovedEvent
-    if not hasDeprecatedMethods(ob):
-        return
     container = event.newParent
     if container is None:
         # this is a remove
@@ -182,9 +222,6 @@
 def callManageBeforeDelete(ob, event):
     """Compatibility subscriber for manage_beforeDelete.
     """
-    # used for ISimpleItem/IObjectManager, IObjectMovedEvent
-    if not hasDeprecatedMethods(ob):
-        return
     container = event.oldParent
     if container is None:
         # this is an add
@@ -212,9 +249,6 @@
 def callManageAfterClone(ob, event):
     """Compatibility subscriber for manage_afterClone.
     """
-    # used for ISimpleItem/IObjectManager, IObjectMovedEvent
-    if not hasDeprecatedMethods(ob):
-        return
     if not isFiveMethod(ob.manage_afterClone):
         warnings.warn(
             "Calling %s.manage_afterClone is deprecated when using Five, "
@@ -620,7 +654,7 @@
 from OFS.OrderSupport import OrderSupport
 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2Base
 
-def doMonkies(transitional, info=None):
+def doMonkies(transitional, info=None, register_cleanup=True):
     """Monkey patch various methods to provide container events.
 
     If passed, ``info`` is a zconfig information about where the
@@ -663,9 +697,11 @@
     patchMethod(OrderSupport, '_old_manage_renameObject',
                 manage_renameObject)
 
+    # XXX remove this for Five 1.3, and put it in configure.zcml
     zcml.load_config('event.zcml', Products.Five)
 
-    addCleanUp(undoMonkies)
+    if register_cleanup:
+        addCleanUp(undoMonkies)
 
 def patchMethod(class_, name, new_method):
     method = getattr(class_, name, None)

Modified: z3/Five/trunk/event.zcml
==============================================================================
--- z3/Five/trunk/event.zcml	(original)
+++ z3/Five/trunk/event.zcml	Wed Oct 26 18:55:12 2005
@@ -1,82 +1,40 @@
 <configure xmlns="http://namespaces.zope.org/zope">
 
+  <!-- needed to call this during init code -->
+  <!-- XXX not needed in Five 1.3, when included by configure.zcml -->
   <include package="zope.app.component" file="meta.zcml" />
 
+  <!-- Adapter giving sublocations for ObjectManagers, used
+       by dispatchToSublocations -->
+
   <adapter
       for="OFS.interfaces.IObjectManager"
       provides="zope.app.location.interfaces.ISublocations"
       factory=".event.ObjectManagerSublocations"
       />
 
-  <!-- Ordering of the following subscribers is important -->
-
-  <!-- dispatch IObjectWillBeMovedEvent to sublocation before
-       compatibility calls, to have "bottom-up" semantics -->
-
-  <subscriber
-      for="OFS.interfaces.IObjectManager
-           .event.IObjectWillBeMovedEvent"
-      factory="zope.app.container.contained.dispatchToSublocations"
-      />
-
-  <!-- manage_beforeDelete compatibility -->
+  <!-- dispatch IObjectWillBeMovedEvent with "bottom-up" semantics -->
 
   <subscriber
-      for="OFS.interfaces.ISimpleItem
+      for="OFS.interfaces.IItem
            .event.IObjectWillBeMovedEvent"
-      factory=".event.callManageBeforeDelete"
+      factory=".event.dispatchObjectWillBeMovedEvent"
       />
 
-  <subscriber
-      for="OFS.interfaces.IObjectManager
-           .event.IObjectWillBeMovedEvent"
-      factory=".event.callManageBeforeDelete"
-      />
-
-  <!-- manage_afterAdd compatibility -->
-
-  <subscriber
-      for="OFS.interfaces.ISimpleItem
-           zope.app.container.interfaces.IObjectMovedEvent"
-      factory=".event.callManageAfterAdd"
-      />
+  <!-- dispatch IObjectMovedEvent with "top-down" semantics -->
 
   <subscriber
-      for="OFS.interfaces.IObjectManager
+      for="OFS.interfaces.IItem
            zope.app.container.interfaces.IObjectMovedEvent"
-      factory=".event.callManageAfterAdd"
-      />
-
-  <!-- dispatch IObjectMovedEvent to sublocations after
-       compatibility calls, to have "top-down" semantics -->
-
-  <subscriber
-      for="OFS.interfaces.IObjectManager
-           zope.app.container.interfaces.IObjectMovedEvent"
-      factory="zope.app.container.contained.dispatchToSublocations"
-      />
-
-  <!-- manage_afterClone compatibility -->
-
-  <subscriber
-      for="OFS.interfaces.ISimpleItem
-           .event.IFiveObjectClonedEvent"
-      factory=".event.callManageAfterClone"
-      />
-
-  <subscriber
-      for="OFS.interfaces.IObjectManager
-           .event.IFiveObjectClonedEvent"
-      factory=".event.callManageAfterClone"
+      factory=".event.dispatchObjectMovedEvent"
       />
 
-  <!-- dispatch IFiveObjectClonedEvent to sublocations after
-       compatibility calls, to have "top-down" semantics -->
+  <!-- dispatch IFiveObjectClonedEvent with "top-down" semantics -->
 
   <subscriber
-      for="OFS.interfaces.IObjectManager
+      for="OFS.interfaces.IItem
            .event.IFiveObjectClonedEvent"
-      factory="zope.app.container.contained.dispatchToSublocations"
+      factory=".event.dispatchFiveObjectClonedEvent"
       />
 
 </configure>

Modified: z3/Five/trunk/monkey.py
==============================================================================
--- z3/Five/trunk/monkey.py	(original)
+++ z3/Five/trunk/monkey.py	Wed Oct 26 18:55:12 2005
@@ -59,3 +59,10 @@
 
     from zope.app.component import localservice
     localservice.getLocalServices = getLocalServices
+
+    # XXX in Five 1.3, call this from here:
+    if False: # XXX
+        from Products.Five import event
+        event.doMonkies(transitional=False,
+                        info='Five/monkey.py',
+                        register_cleanup=False)

Modified: z3/Five/trunk/tests/event.txt
==============================================================================
--- z3/Five/trunk/tests/event.txt	(original)
+++ z3/Five/trunk/tests/event.txt	Wed Oct 26 18:55:12 2005
@@ -110,8 +110,7 @@
   >>> from zope.app.container.interfaces import IObjectMovedEvent
   >>> from Products.Five.event import IObjectWillBeMovedEvent
   >>> from Products.Five.event import IFiveObjectClonedEvent
-  >>> from OFS.interfaces import IObjectManager
-  >>> from OFS.interfaces import ISimpleItem
+  >>> from OFS.interfaces import IItem
   >>> from zope.app.tests import ztapi
   >>> def printObjectEvent(object, event):
   ...     print event.__class__.__name__, object.getId()
@@ -121,12 +120,9 @@
   ...         IFiveObjectClonedEvent.providedBy(event)):
   ...         return
   ...     print event.__class__.__name__, object.getId()
-  >>> ztapi.handle([IObjectManager, IObjectMovedEvent], printObjectEvent)
-  >>> ztapi.handle([ISimpleItem, IObjectMovedEvent], printObjectEvent)
-  >>> ztapi.handle([IObjectManager, IObjectWillBeMovedEvent], printObjectEvent)
-  >>> ztapi.handle([ISimpleItem, IObjectWillBeMovedEvent], printObjectEvent)
-  >>> ztapi.handle([IObjectManager, IFiveObjectClonedEvent], printObjectEvent)
-  >>> ztapi.handle([ISimpleItem, IFiveObjectClonedEvent], printObjectEvent)
+  >>> ztapi.handle([IItem, IObjectMovedEvent], printObjectEvent)
+  >>> ztapi.handle([IItem, IObjectWillBeMovedEvent], printObjectEvent)
+  >>> ztapi.handle([IItem, IFiveObjectClonedEvent], printObjectEvent)
   >>> ztapi.handle([None, IObjectEvent], printObjectEventExceptSome)
 
 Phase 1


More information about the z3-checkins mailing list