[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces - location.py:1.1.2.1 container.py:1.3.2.1 zapi.py:1.8.20.1 context.py:NONE

Jim Fulton jim at zope.com
Mon Sep 8 15:22:23 EDT 2003


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

Modified Files:
      Tag: parentgeddon-branch
	container.py zapi.py 
Added Files:
      Tag: parentgeddon-branch
	location.py 
Removed Files:
      Tag: parentgeddon-branch
	context.py 
Log Message:
Checking in work in progress on parentgeddon-branch so Fred can help
me to get the tests passing.  Specific log entries will be provided
when we merge this into the head.


=== Added File Zope3/src/zope/app/interfaces/location.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Location framework

$Id: location.py,v 1.1.2.1 2003/09/08 18:21:21 jim Exp $
"""

from zope.interface import Interface, Attribute
from zope import schema

class ILocation(Interface):
    """Objects that have a structural location
    """

    __parent__ = Attribute("The parent in the location hierarchy")

    __name__ = schema.TextLine(
        __doc__=
        """The name within the parent

        The parent can be traversed with this name to get the object.
        """)


=== Zope3/src/zope/app/interfaces/container.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/interfaces/container.py:1.3	Fri Sep  5 14:52:40 2003
+++ Zope3/src/zope/app/interfaces/container.py	Mon Sep  8 14:21:21 2003
@@ -20,6 +20,8 @@
 from zope.component.interfaces import IView
 from zope.interface.common.mapping import IItemMapping
 from zope.interface.common.mapping import IReadMapping, IEnumerableMapping
+from zope.app.interfaces.location import ILocation
+from zope.app.interfaces.event import IObjectEvent
 
 class DuplicateIDError(KeyError):
     pass
@@ -27,42 +29,10 @@
 class ContainerError(Exception):
     """An error of a container with one of its components."""
 
-class CopyException(Exception):
-    """An error that occurred within a copy operation."""
-
-    def __init__(self, container, key, message=""):
-        self.container = container
-        self.key = key
-        self.message = message and ": %s" % message
-
-    def __str__(self):
-        return ("%(key)s cannot be copied "
-                "from %(container)s%(message)s" % self.__dict__)
-
-class MoveException(Exception):
-    """An error that occurred within a move operation."""
-
-    def __init__(self, container, key, message=""):
-        self.container = container
-        self.key = key
-        self.message = message and ": %s" % message
-
-    def __str__(self):
-        return ("%(key)s cannot be copied "
-                "from %(container)s%(message)s" % self.__dict__)
-
-class UnaddableError(ContainerError):
-    """An object cannot be added to a container."""
-
-    def __init__(self, container, obj, message=""):
-        self.container = container
-        self.obj = obj
-        self.message = message and ": %s" % message
-
-    def __str__(self):
-        return ("%(obj)s cannot be added "
-                "to %(container)s%(message)s" % self.__dict__)
 
+class IContained(ILocation):
+    """Objects contained in containers
+    """
 
 class IItemContainer(IItemMapping):
     """Minimal readable container
@@ -91,6 +61,17 @@
         Raises a TypeError if the key is not a unicode or ascii string.
 
         Returns the key used, which might be different than the given key.
+
+        If the object doesn't implement IContained, then one of two
+        things must be done:
+
+        1. If the object implements ILocation, then the IContained
+           interface must be declared for the object.
+
+        2. Otherwise, a ContainedProxy is created for the object and
+           stored.
+
+        The object's __parent__ and __name__ attributes are set.
         """
 
     def __delitem__(key):
@@ -124,14 +105,28 @@
         Raises ValueError if order contains an invalid set of keys.
         """
 
-class IOptionalNamesContainer(IContainer):
-    """Containers that will choose names for their items if no names are given
-    """
-
 class IContainerNamesContainer(IContainer):
     """Containers that always choose names for their items
     """
 
+
+##############################################################################
+# Adding objects
+
+class UnaddableError(ContainerError):
+    """An object cannot be added to a container."""
+
+    def __init__(self, container, obj, message=""):
+        self.container = container
+        self.obj = obj
+        self.message = message and ": %s" % message
+
+    def __str__(self):
+        return ("%(obj)s cannot be added "
+                "to %(container)s%(message)s" % self.__dict__)
+
+# See zope.app.interfaces.event.IObjectAddedEvent
+
 class IAdding(IView):
 
     def add(content):
@@ -163,101 +158,89 @@
         decide what page to display after content is added.
         """
 
-class IZopeItemContainer(IItemContainer):
-
-    def __getitem__(key):
-        """Return the content for the given key
-
-        Raises KeyError if the content can't be found.
+class IAddNotifiable(Interface):
+    """Interface for notification of being added."""
 
-        The returned value will be in the context of the container.
-        """
+    def afterAddHook(object, container):
+        """Hook method will call after an object is added to container."""
 
-class IZopeSimpleReadContainer(IZopeItemContainer, ISimpleReadContainer):
-    """Readable content containers
-    """
 
-    def get(key, default=None):
-        """Get a value for a key
+class IAddTarget(Interface):
 
-        The default is returned if there is no value for the key.
+    def acceptsObject(key, obj):
+        '''Allow the container to say if it accepts the given object.
 
-        The value for the key will be in the context of the container.
-        """
+        Returns True if the object would be accepted as contents of
+        this container. Otherwise, returns False.
+        '''
 
-class IZopeReadContainer(IZopeSimpleReadContainer, IReadContainer):
-    """Readable containers that can be enumerated.
-    """
+    def addObject(key, obj):
+        '''Add the given object to the container under the given key.
 
-    def values():
-        """Return the values of the mapping object in the context of
-           the container
-        """
+        Raises a ValueError if key is an empty string, unless the
+        this object chooses a different key.
 
-    def items():
-        """Return the items of the mapping object in the context
-           of the container
-        """
+        Returns the key used, which might be different than the
+        given key.
 
+        This method must issue an IObjectAddedEvent, and it must 
+        call the afterAddHook hook of the object.
+        It must publish an IObjectModified event for the
+        container.
+        '''
 
-class IZopeWriteContainer(IWriteContainer):
-    """An interface for the write aspects of a container."""
+class INameChooser(Interface):
 
-    def setObject(key, object):
-        """Add the given object to the container under the given key.
+    def chooseName(name, object):
+        """Choose a name for the object
 
-        Raises a ValueError if key is an empty string, unless the
-        context wrapper chooses a different key.
+        The given name and object may be taken into account when
+        choosing the name.
 
-        Returns the key used, which might be different than the given key.
+        """
 
-        If the object has an adpter to IAddNotifiable then the afterAddHook
-        method on the adpter will be called after the object is added.
+class IPasteTarget(Interface):
 
-        An IObjectAddedEvent will be published after the object is added and
-        after afterAddHook is called. The event object will be the added
-        object in the context of the container
+    def acceptsObject(key, obj):
+        '''Allow the container to say if it accepts the given wrapped object.
 
-        An IObjectModifiedEvent will be published after the IObjectAddedEvent
-        is published. The event object will be the container.
-        """
+        Returns True if the object would be accepted as contents of
+        this container. Otherwise, returns False.
+        '''
 
-    def __delitem__(key):
-        """Delete the keyed object from the context of the container.
+    def pasteObject(key, obj):
+        '''Add the given object to the container under the given key.
 
-        Raises a KeyError if the object is not found.
+        Raises a ValueError if key is an empty string, unless the
+        this object chooses a different key.
 
-        If the object has an adpter to IDeleteNotifiable then the
-        beforeDeleteHook method on the adpter will be called before
-        the object is removed.
-
-        An IObjectRemovedEvent will be published before the object is
-        removed and before beforeDeleteHook method is called.
-        The event object will be the removed from the context of the container
+        Returns the key used, which might be different than the
+        given key.
 
-        An IObjectModifiedEvent will be published after the
-        IObjectRemovedEvent is published. The event object will be the
+        This method must not issue an IObjectAddedEvent, nor must it
+        call the afterAddHook hook of the object.
+        However, it must publish an IObjectModified event for the
         container.
-        """
-
-class IZopeItemWriteContainer(IZopeWriteContainer, IZopeItemContainer):
-    """An IZopeWriteContainer for writable item containers.
+        '''
 
-    'setObject' and '__delitem__' of IZopeWriteContainer imply being able
-    to get at an object after it has been added to the container, or
-    before it has been deleted from the container.
-    This interface makes that contract explicit, and also offers to
-    make '__getitem__' context-aware.
+class IPasteNamesChooser(Interface):
+    """Containers automatically chooses a new name for the object if the
+    given one is already choosen.
     """
 
-class IZopeContainer(IZopeReadContainer, IZopeWriteContainer, IContainer):
-    """Readable and writable content container."""
+    def getNewName(obj, key):
+        """ Should return a choosen name based on object and key to be used
+        for pasting. This may not be reliable all the time as
+        the name you choose is not guaranteed to be reserved between the time
+        you get it and the time you paste the object, so be careful."""
 
-class IAddNotifiable(Interface):
-    """Interface for notification of being added."""
+# Removing objects
 
-    def afterAddHook(object, container):
-        """Hook method will call after an object is added to container."""
+
+class IObjectRemovedEvent(IObjectEvent):
+    """An object has been removed from a container"""
+
+    fromLocation = Attribute("The old location for the object.")
 
 class IDeleteNotifiable(Interface):
     """Interface for notification of being deleted."""
@@ -265,26 +248,17 @@
     def beforeDeleteHook(object, container):
         """Hook method will call before object is removed from container."""
 
-class IMoveNotifiable(IDeleteNotifiable, IAddNotifiable):
-    """Interface for notification of being deleted, added, or moved."""
+class IRemoveSource(Interface):
 
-    def beforeDeleteHook(object, container, movingTo=None):
-        """Hook method will call before object is removed from container.
-
-        If the object is being moved, 'movingTo' will be the unicode path
-        the object is being moved to.
-        If the object is simply being deleted and not being moved, 'movingTo'
-        will be None.
-        """
+    def removeObject(key):
+        '''Remove the object with the given key
 
-    def afterAddHook(object, container, movedFrom=None):
-        """Hook method will call after an object is added to container.
+        This method should publish an IObjectRemovedEvent, and should
+        call the afterDeleteHook method of the object.
+        It must publish an IObjectModified event for the container.
+        '''
 
-        If the object is being moved, 'movedFrom' will be the unicode path
-        the object was moved from.
-        If the object is simply being added and not being moved, 'movedFrom'
-        will be None.
-        """
+# Copying objects
 
 class ICopyNotifiable(IAddNotifiable):
 
@@ -303,42 +277,18 @@
         argument, to avoid confusion if the object is both
         IMoveNotifiable and ICopyNotifiable.  """
 
-class IPasteTarget(Interface):
-
-    def acceptsObject(key, obj):
-        '''Allow the container to say if it accepts the given wrapped
-        object.
 
-        Returns True if the object would be accepted as contents of
-        this container. Otherwise, returns False.
-        '''
-
-    def pasteObject(key, obj):
-        '''Add the given object to the container under the given key.
-
-        Raises a ValueError if key is an empty string, unless the
-        this object chooses a different key.
-
-        Returns the key used, which might be different than the
-        given key.
-
-        This method must not issue an IObjectAddedEvent, nor must it
-        call the afterAddHook hook of the object.
-        However, it must publish an IObjectModified event for the
-        container.
-        '''
-
-class IMoveSource(Interface):
+class CopyException(Exception):
+    """An error that occurred within a copy operation."""
 
-    def removeObject(key, movingTo):
-        '''Remove and return the object with the given key, as the
-        first part of a move.
+    def __init__(self, container, key, message=""):
+        self.container = container
+        self.key = key
+        self.message = message and ": %s" % message
 
-        movingTo is the unicode path for where the move is to.
-        This method should not publish an IObjectRemovedEvent, nor should
-        it call the afterDeleteHook method of the object.
-        However, it must publish an IObjectModified event for the container.
-        '''
+    def __str__(self):
+        return ("%(key)s cannot be copied "
+                "from %(container)s%(message)s" % self.__dict__)
 
 class ICopySource(Interface):
 
@@ -360,14 +310,50 @@
         May return None if its not possible to get a copy without children.
         '''
 
-class IPasteNamesChooser(Interface):
-    """Containers automatically chooses a new name for the object if the
-    given one is already choosen.
-    """
+# Moving Objects
 
-    def getNewName(obj, key):
-        """ Should return a choosen name based on object and key to be used
-        for pasting. This may not be reliable all the time as
-        the name you choose is not guaranteed to be reserved between the time
-        you get it and the time you paste the object, so be careful."""
+class MoveException(Exception):
+    """An error that occurred within a move operation."""
+
+    def __init__(self, container, key, message=""):
+        self.container = container
+        self.key = key
+        self.message = message and ": %s" % message
+
+    def __str__(self):
+        return ("%(key)s cannot be copied "
+                "from %(container)s%(message)s" % self.__dict__)
+
+class IMoveNotifiable(IDeleteNotifiable, IAddNotifiable):
+    """Interface for notification of being deleted, added, or moved."""
+
+    def beforeDeleteHook(object, container, movingTo=None):
+        """Hook method will call before object is removed from container.
+
+        If the object is being moved, 'movingTo' will be the unicode path
+        the object is being moved to.
+        If the object is simply being deleted and not being moved, 'movingTo'
+        will be None.
+        """
+
+    def afterAddHook(object, container, movedFrom=None):
+        """Hook method will call after an object is added to container.
+
+        If the object is being moved, 'movedFrom' will be the unicode path
+        the object was moved from.
+        If the object is simply being added and not being moved, 'movedFrom'
+        will be None.
+        """
+
+class IMoveSource(Interface):
+
+    def removeObject(key, movingTo):
+        '''Remove and return the object with the given key, as the
+        first part of a move.
+
+        movingTo is the unicode path for where the move is to.
+        This method should not publish an IObjectRemovedEvent, nor should
+        it call the afterDeleteHook method of the object.
+        However, it must publish an IObjectModified event for the container.
+        '''
 


=== Zope3/src/zope/app/interfaces/zapi.py 1.8 => 1.8.20.1 ===
--- Zope3/src/zope/app/interfaces/zapi.py:1.8	Thu Jun 26 22:50:11 2003
+++ Zope3/src/zope/app/interfaces/zapi.py	Mon Sep  8 14:21:21 2003
@@ -16,16 +16,10 @@
 $Id$
 """
 from zope.component.interfaces import IComponentArchitecture
-from zope.app.interfaces.context import IContextWrapper
-from zope.context.interfaces import IWrapperIntrospection
-from zope.context.interfaces import IContextAwareDescriptorSupport
 from zope.app.interfaces.traversing import ITraversalAPI
 
 class IZAPI(
     IComponentArchitecture,
-    IContextWrapper,
-    IWrapperIntrospection,
-    IContextAwareDescriptorSupport,
     ITraversalAPI,
     ):
     """Convenience API for use with Zope applications.

=== Removed File Zope3/src/zope/app/interfaces/context.py ===




More information about the Zope3-Checkins mailing list