Commit df0a79ea authored by Chris McDonough's avatar Chris McDonough

Merge "movedaddedremoved" branch:

- Rid ourselves of ``IObjectMovedEvent``, ``IObjectAddedEvent``,
  ``IObjectRemovedEvent`` interfaces and ``ObjectMovedEvent``,
  ``ObjectAddedEvent`` and ``ObjectRemovedEvent`` classes.  All of
  these were moved to ``zope.lifecycleevent``. Depend on
  ``zope.lifecycleevent``>=3.5.2.

parent a211c624
......@@ -4,6 +4,13 @@ CHANGES
3.8.2 (unreleased)
------------------
- Rid ourselves of ``IObjectMovedEvent``, ``IObjectAddedEvent``,
``IObjectRemovedEvent`` interfaces and ``ObjectMovedEvent``,
``ObjectAddedEvent`` and ``ObjectRemovedEvent`` classes. All of
these were moved to ``zope.lifecycleevent``. Depend on
``zope.lifecycleevent``>=3.5.2.
- Fix a bug in OrderedContainer where trying to set the value for a
key that already exists (duplication error) would actually delete the
key from the order, leaving a dangling reference.
......
......@@ -72,7 +72,7 @@ setup(name='zope.container',
'zope.event',
'zope.location',
'zope.security',
'zope.lifecycleevent',
'zope.lifecycleevent>=3.5.2',
'zope.i18nmessageid',
'zope.filerepresentation',
'zope.size',
......
......@@ -59,13 +59,13 @@
<subscriber
zcml:condition="installed zope.app.dependable"
handler=".dependency.CheckDependency"
for="zope.container.interfaces.IObjectRemovedEvent"
for="zope.lifecycleevent.interfaces.IObjectRemovedEvent"
trusted="y"
/>
<subscriber
for="zope.location.interfaces.ILocation
zope.container.interfaces.IObjectMovedEvent"
zope.lifecycleevent.interfaces.IObjectMovedEvent"
handler=".contained.dispatchToSublocations"
>
Handler dispatches moved events to sublocations of the original object.
......
......@@ -23,7 +23,6 @@ from zope.interface import providedBy
from zope.interface.declarations import getObjectSpecification
from zope.interface.declarations import ObjectSpecification
from zope.event import notify
from zope.component.interfaces import ObjectEvent
from zope.location.interfaces import ILocation, ISublocations
from zope.security.checker import selectChecker, CombinedChecker
from zope.lifecycleevent import ObjectModifiedEvent
......@@ -32,12 +31,14 @@ from zope.container.i18n import ZopeMessageFactory as _
from zope.container.interfaces import IContained
from zope.container.interfaces import INameChooser
from zope.container.interfaces import IReservedNames, NameReserved
from zope.container.interfaces import IObjectAddedEvent
from zope.container.interfaces import IObjectMovedEvent
from zope.container.interfaces import IObjectRemovedEvent
from zope.container.interfaces import IContainerModifiedEvent
from zope.container._zope_container_contained import ContainedProxyBase
from zope.container._zope_container_contained import getProxiedObject
from zope.lifecycleevent import ObjectMovedEvent
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent
from zope.broken.interfaces import IBroken
class Contained(object):
......@@ -47,42 +48,6 @@ class Contained(object):
__parent__ = __name__ = None
class ObjectMovedEvent(ObjectEvent):
"""An object has been moved"""
zope.interface.implements(IObjectMovedEvent)
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 ObjectAddedEvent(ObjectMovedEvent):
"""An object has been added to a container"""
zope.interface.implements(IObjectAddedEvent)
def __init__(self, object, newParent=None, newName=None):
if newParent is None:
newParent = object.__parent__
if newName is None:
newName = object.__name__
ObjectMovedEvent.__init__(self, object, None, None, newParent, newName)
class ObjectRemovedEvent(ObjectMovedEvent):
"""An object has been removed from a container"""
zope.interface.implements(IObjectRemovedEvent)
def __init__(self, object, oldParent=None, oldName=None):
if oldParent is None:
oldParent = object.__parent__
if oldName is None:
oldName = object.__name__
ObjectMovedEvent.__init__(self, object, oldParent, oldName, None, None)
class ContainerModifiedEvent(ObjectModifiedEvent):
"""The container has been modified."""
......@@ -147,6 +112,7 @@ def dispatchToSublocations(object, event):
Now we'll register it:
>>> from zope import component
>>> from zope.lifecycleevent.interfaces import IObjectMovedEvent
>>> component.provideHandler(handler, [None, IObjectMovedEvent])
We also register our dispatcher:
......@@ -380,8 +346,8 @@ def setitem(container, setitemf, name, object):
... def setMoved(self, event):
... self.moved = event
>>> from zope.container.interfaces import IObjectAddedEvent
>>> from zope.container.interfaces import IObjectMovedEvent
>>> from zope.lifecycleevent.interfaces import IObjectAddedEvent
>>> from zope.lifecycleevent.interfaces import IObjectMovedEvent
>>> from zope import component
>>> component.provideHandler(lambda obj, event: obj.setAdded(event),
......@@ -600,7 +566,7 @@ def uncontained(object, container, name=None):
>>> from zope.component.eventtesting import getEvents
>>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
>>> from zope.container.interfaces import IObjectRemovedEvent
>>> from zope.lifecycleevent.interfaces import IObjectRemovedEvent
We'll start by creating a container with an item:
......
......@@ -17,14 +17,21 @@ $Id$
"""
__docformat__ = 'restructuredtext'
from zope.interface import Interface, Attribute, Invalid
from zope.interface import Interface, Invalid
from zope.interface.common.mapping import IItemMapping
from zope.interface.common.mapping import IReadMapping, IEnumerableMapping
from zope.component.interfaces import IObjectEvent
from zope.lifecycleevent.interfaces import IObjectModifiedEvent
from zope.location.interfaces import ILocation
from zope.schema import Set
from zope.lifecycleevent.interfaces import IObjectModifiedEvent
# the following imports provide backwards compatibility for consumers;
# do not remove them
from zope.lifecycleevent.interfaces import IObjectMovedEvent
from zope.lifecycleevent.interfaces import IObjectAddedEvent
from zope.lifecycleevent.interfaces import IObjectRemovedEvent
# /end backwards compatibility imports
from zope.container.i18n import ZopeMessageFactory as _
class DuplicateIDError(KeyError):
......@@ -214,18 +221,6 @@ class IReservedNames(Interface):
class NameReserved(ValueError):
__doc__ = _("""The name is reserved for this container""")
##############################################################################
# Moving Objects
class IObjectMovedEvent(IObjectEvent):
"""An object has been 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.")
##############################################################################
# Adding objects
......@@ -242,10 +237,6 @@ class UnaddableError(ContainerError):
"to %(container)s%(message)s" % self.__dict__)
class IObjectAddedEvent(IObjectMovedEvent):
"""An object has been added to a container."""
class INameChooser(Interface):
def checkName(name, object):
......@@ -266,14 +257,6 @@ class INameChooser(Interface):
"""
##############################################################################
# Removing objects
class IObjectRemovedEvent(IObjectMovedEvent):
"""An object has been removed from a container."""
##############################################################################
# Modifying containers
......
......@@ -19,7 +19,7 @@ import unittest
from zope.interface import implements
from zope.app.dependable.interfaces import IDependable, DependencyError
from zope.container.contained import ObjectRemovedEvent
from zope.lifecycleevent import ObjectRemovedEvent
from zope.container.dependency import CheckDependency
from zope.traversing.interfaces import IPhysicallyLocatable
......
......@@ -69,8 +69,9 @@ def test_all_items_available_at_object_added_event():
>>> import zope.component
>>> from zope.container import interfaces
>>> from zope.lifecycleevent.interfaces import IObjectAddedEvent
>>> @zope.component.adapter(interfaces.IObjectAddedEvent)
>>> @zope.component.adapter(IObjectAddedEvent)
... def printContainerKeys(event):
... print event.newParent.keys()
......@@ -97,8 +98,9 @@ def test_exception_causes_order_fix():
>>> import zope.component
>>> from zope.container import interfaces
>>> from zope.lifecycleevent.interfaces import IObjectAddedEvent
>>> @zope.component.adapter(interfaces.IObjectAddedEvent)
>>> @zope.component.adapter(IObjectAddedEvent)
... def raiseException(event):
... raise Exception()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment