[z3-checkins] r19413 - in z3/Five/trunk: . tests
efge at codespeak.net
efge at codespeak.net
Wed Nov 2 15:37:52 CET 2005
Author: efge
Date: Wed Nov 2 15:37:52 2005
New Revision: 19413
Removed:
z3/Five/trunk/event.py
z3/Five/trunk/subscribers.py
Modified:
z3/Five/trunk/event.zcml
z3/Five/trunk/eventconfigure.py
z3/Five/trunk/tests/event.txt
Log:
Moved interfaces, subscribers and events into Zope itself.
Renamed IFiveObjectClonedEvent to IObjectClonedEvent.
Deleted: /z3/Five/trunk/event.py
==============================================================================
--- /z3/Five/trunk/event.py Wed Nov 2 15:37:52 2005
+++ (empty file)
@@ -1,90 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-Five event definitions.
-
-$Id$
-"""
-
-import warnings
-
-from zope.interface import implements
-from zope.interface import Attribute
-from zope.app.event.interfaces import IObjectEvent
-from zope.app.event.objectevent import ObjectEvent
-
-
-class IObjectWillBeMovedEvent(IObjectEvent):
- """An object will be moved."""
- oldParent = Attribute("The old location parent for the object.")
- oldName = Attribute("The old location name for the object.")
- newParent = Attribute("The new location parent for the object.")
- newName = Attribute("The new location name for the object.")
-
-class IObjectWillBeAddedEvent(IObjectWillBeMovedEvent):
- """An object will be added to a container."""
-
-class IObjectWillBeRemovedEvent(IObjectWillBeMovedEvent):
- """An object will be removed from a container"""
-
-class IFiveObjectClonedEvent(IObjectEvent):
- """An object has been cloned (a la Zope 2).
-
- This is for Zope 2 compatibility, subscribers should really use
- IObjectCopiedEvent or IObjectAddedEvent, depending on their use
- cases.
-
- event.object is the copied object, already added to its container.
- Note that this event is dispatched to all sublocations.
- """
-
-
-class ObjectWillBeMovedEvent(ObjectEvent):
- """An object will be moved"""
- implements(IObjectWillBeMovedEvent)
-
- def __init__(self, object, oldParent, oldName, newParent, newName):
- ObjectEvent.__init__(self, object)
- self.oldParent = oldParent
- self.oldName = oldName
- self.newParent = newParent
- self.newName = newName
-
-class ObjectWillBeAddedEvent(ObjectWillBeMovedEvent):
- """An object will be added to a container"""
- implements(IObjectWillBeAddedEvent)
-
- def __init__(self, object, newParent=None, newName=None):
- #if newParent is None:
- # newParent = object.__parent__
- #if newName is None:
- # newName = object.__name__
- ObjectWillBeMovedEvent.__init__(self, object, None, None,
- newParent, newName)
-
-class ObjectWillBeRemovedEvent(ObjectWillBeMovedEvent):
- """An object will be removed from a container"""
- implements(IObjectWillBeRemovedEvent)
-
- def __init__(self, object, oldParent=None, oldName=None):
- #if oldParent is None:
- # oldParent = object.__parent__
- #if oldName is None:
- # oldName = object.__name__
- ObjectWillBeMovedEvent.__init__(self, object, oldParent, oldName,
- None, None)
-
-class FiveObjectClonedEvent(ObjectEvent):
- implements(IFiveObjectClonedEvent)
-
Modified: z3/Five/trunk/event.zcml
==============================================================================
--- z3/Five/trunk/event.zcml (original)
+++ z3/Five/trunk/event.zcml Wed Nov 2 15:37:52 2005
@@ -1,24 +1,20 @@
<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=".subscribers.ObjectManagerSublocations"
+ factory="OFS.subscribers.ObjectManagerSublocations"
/>
<!-- dispatch IObjectWillBeMovedEvent with "bottom-up" semantics -->
<subscriber
for="OFS.interfaces.IItem
- .event.IObjectWillBeMovedEvent"
- handler=".subscribers.dispatchObjectWillBeMovedEvent"
+ OFS.interfaces.IObjectWillBeMovedEvent"
+ handler="OFS.subscribers.dispatchObjectWillBeMovedEvent"
/>
<!-- dispatch IObjectMovedEvent with "top-down" semantics -->
@@ -26,15 +22,15 @@
<subscriber
for="OFS.interfaces.IItem
zope.app.container.interfaces.IObjectMovedEvent"
- handler=".subscribers.dispatchObjectMovedEvent"
+ handler="OFS.subscribers.dispatchObjectMovedEvent"
/>
- <!-- dispatch IFiveObjectClonedEvent with "top-down" semantics -->
+ <!-- dispatch IObjectClonedEvent with "top-down" semantics -->
<subscriber
for="OFS.interfaces.IItem
- .event.IFiveObjectClonedEvent"
- handler=".subscribers.dispatchFiveObjectClonedEvent"
+ OFS.interfaces.IObjectClonedEvent"
+ handler="OFS.subscribers.dispatchObjectClonedEvent"
/>
</configure>
Modified: z3/Five/trunk/eventconfigure.py
==============================================================================
--- z3/Five/trunk/eventconfigure.py (original)
+++ z3/Five/trunk/eventconfigure.py Wed Nov 2 15:37:52 2005
@@ -19,7 +19,7 @@
"""
import warnings
-from Products.Five.subscribers import deprecatedManageAddDeleteClasses
+from OFS.subscribers import deprecatedManageAddDeleteClasses
def setContainerEvents():
warnings.warn("Using <five:containerEvents/> is deprecated (it is now "
Deleted: /z3/Five/trunk/subscribers.py
==============================================================================
--- /z3/Five/trunk/subscribers.py Wed Nov 2 15:37:52 2005
+++ (empty file)
@@ -1,158 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-Five subscriber definitions.
-
-$Id$
-"""
-
-import warnings
-import sys
-
-from zLOG import LOG, ERROR
-from App.config import getConfiguration
-from AccessControl import getSecurityManager
-from ZODB.POSException import ConflictError
-import OFS.ObjectManager
-import OFS.interfaces
-
-from zope.interface import implements
-from zope.component import adapts
-from zope.app.container.contained import dispatchToSublocations
-from zope.app.location.interfaces import ISublocations
-
-
-deprecatedManageAddDeleteClasses = []
-
-
-def hasDeprecatedMethods(ob):
- """Do we need to call the deprecated methods?
- """
- for class_ in deprecatedManageAddDeleteClasses:
- if isinstance(ob, class_):
- return True
- return False
-
-def maybeCallDeprecated(method_name, ob, *args):
- """Call a deprecated method, if the framework doesn't call it already.
- """
- if hasDeprecatedMethods(ob):
- # Already deprecated through zcml
- return
- method = getattr(ob, method_name)
- if getattr(method, '__five_method__', False):
- # Method knows it's deprecated
- return
- if deprecatedManageAddDeleteClasses:
- # Not deprecated through zcml and directives fully loaded
- class_ = ob.__class__
- warnings.warn(
- "Calling %s.%s.%s is deprecated when using Five, "
- "instead use event subscribers or "
- "mark the class with <five:deprecatedManageAddDelete/>"
- % (class_.__module__, class_.__name__, method_name),
- DeprecationWarning)
- # Note that calling the method can lead to incorrect behavior
- # but in the most common case that's better than not calling it.
- method(ob, *args)
-
-##################################################
-
-class ObjectManagerSublocations(object):
- """Get the sublocations for an ObjectManager.
- """
- adapts(OFS.interfaces.IObjectManager)
- implements(ISublocations)
-
- def __init__(self, container):
- self.container = container
-
- def sublocations(self):
- for ob in self.container.objectValues():
- yield ob
-
-# 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 OFS.interfaces.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 OFS.interfaces.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 OFS.interfaces.IObjectManager.providedBy(ob):
- dispatchToSublocations(ob, event)
-
-
-def callManageAfterAdd(ob, event):
- """Compatibility subscriber for manage_afterAdd.
- """
- container = event.newParent
- if container is None:
- # this is a remove
- return
- ob.manage_afterAdd(event.object, container)
-
-def callManageBeforeDelete(ob, event):
- """Compatibility subscriber for manage_beforeDelete.
- """
- container = event.oldParent
- if container is None:
- # this is an add
- return
- try:
- ob.manage_beforeDelete(event.object, container)
- except OFS.ObjectManager.BeforeDeleteException:
- raise
- except ConflictError:
- raise
- except:
- LOG('Zope', ERROR, '_delObject() threw', error=sys.exc_info())
- # In debug mode when non-Manager, let exceptions propagate.
- if getConfiguration().debug_mode:
- if not getSecurityManager().getUser().has_role('Manager'):
- raise
-
-def callManageAfterClone(ob, event):
- """Compatibility subscriber for manage_afterClone.
- """
- ob.manage_afterClone(event.object)
Modified: z3/Five/trunk/tests/event.txt
==============================================================================
--- z3/Five/trunk/tests/event.txt (original)
+++ z3/Five/trunk/tests/event.txt Wed Nov 2 15:37:52 2005
@@ -60,28 +60,30 @@
>>> from zope.app.event.interfaces import IObjectEvent
>>> from zope.app.container.interfaces import IObjectMovedEvent
- >>> from Products.Five.event import IObjectWillBeMovedEvent
- >>> from Products.Five.event import IFiveObjectClonedEvent
+ >>> from OFS.interfaces import IObjectWillBeMovedEvent
+ >>> from OFS.interfaces import IObjectClonedEvent
>>> from OFS.interfaces import IItem
>>> def printObjectEvent(object, event):
... print event.__class__.__name__, object.getId()
>>> def printObjectEventExceptSome(object, event):
... if (IObjectMovedEvent.providedBy(event) or
... IObjectWillBeMovedEvent.providedBy(event) or
- ... IFiveObjectClonedEvent.providedBy(event)):
+ ... IObjectClonedEvent.providedBy(event)):
... return
... print event.__class__.__name__, object.getId()
>>> from zope.component import provideHandler
>>> provideHandler(printObjectEvent, (IItem, IObjectMovedEvent))
>>> provideHandler(printObjectEvent, (IItem, IObjectWillBeMovedEvent))
- >>> provideHandler(printObjectEvent, (IItem, IFiveObjectClonedEvent))
+ >>> provideHandler(printObjectEvent, (IItem, IObjectClonedEvent))
>>> provideHandler(printObjectEventExceptSome, (None, IObjectEvent))
Finally we need to load the subscribers configuration::
>>> from Products.Five import zcml
>>> import Products.Five
+ >>> import zope.app.component
+ >>> zcml.load_config('meta.zcml', zope.app.component)
>>> zcml.load_config('event.zcml', Products.Five)
Old class
@@ -163,7 +165,7 @@
ObjectWillBeAddedEvent copy_of_blueberry
ObjectAddedEvent copy_of_blueberry
old manage_afterAdd copy_of_blueberry copy_of_blueberry folder
- FiveObjectClonedEvent copy_of_blueberry
+ ObjectClonedEvent copy_of_blueberry
old manage_afterClone copy_of_blueberry copy_of_blueberry
[{'new_id': 'copy_of_blueberry', 'id': 'blueberry'}]
@@ -182,7 +184,7 @@
ObjectWillBeAddedEvent strawberry
ObjectAddedEvent strawberry
old manage_afterAdd strawberry strawberry folder
- FiveObjectClonedEvent strawberry
+ ObjectClonedEvent strawberry
old manage_afterClone strawberry strawberry
>>> res.getId()
'strawberry'
@@ -240,9 +242,9 @@
old manage_afterAdd mickey mickey folder
ObjectAddedEvent donald
old manage_afterAdd donald mickey folder
- FiveObjectClonedEvent mickey
+ ObjectClonedEvent mickey
old manage_afterClone mickey mickey
- FiveObjectClonedEvent donald
+ ObjectClonedEvent donald
old manage_afterClone donald mickey
>>> res.getId()
'mickey'
@@ -292,7 +294,7 @@
ObjectCopiedEvent copy_of_dilbert
ObjectWillBeAddedEvent copy_of_dilbert
ObjectAddedEvent copy_of_dilbert
- FiveObjectClonedEvent copy_of_dilbert
+ ObjectClonedEvent copy_of_dilbert
[{'new_id': 'copy_of_dilbert', 'id': 'dilbert'}]
Then rename::
@@ -307,7 +309,7 @@
ObjectCopiedEvent phb
ObjectWillBeAddedEvent phb
ObjectAddedEvent phb
- FiveObjectClonedEvent phb
+ ObjectClonedEvent phb
>>> res.getId()
'phb'
@@ -355,8 +357,8 @@
ObjectWillBeAddedEvent mel
ObjectAddedEvent serenity
ObjectAddedEvent mel
- FiveObjectClonedEvent serenity
- FiveObjectClonedEvent mel
+ ObjectClonedEvent serenity
+ ObjectClonedEvent mel
>>> res.getId()
'serenity'
More information about the z3-checkins
mailing list