[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - BTreeContainer.py:1.2 ContainerTraversable.py:1.2 ContainerTraverser.py:1.2 Exceptions.py:1.2 IContainer.py:1.2 IContainerLimit.py:1.2 IOrderedContainer.py:1.2 SampleContainer.py:1.2 __init__.py:1.2 container.zcml:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:26 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/OFS/Container

Added Files:
	BTreeContainer.py ContainerTraversable.py 
	ContainerTraverser.py Exceptions.py IContainer.py 
	IContainerLimit.py IOrderedContainer.py SampleContainer.py 
	__init__.py container.zcml 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/OFS/Container/BTreeContainer.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+This module provides a sample container implementation.
+
+This is primarily for testing purposes.
+
+It might be useful as a mix-in for some classes, but many classes will
+need a very different implementation.
+
+Revision information:
+$Id$
+"""
+
+from Persistence import Persistent
+from Persistence.BTrees.OOBTree import OOBTree
+from Zope.App.OFS.Container.SampleContainer import SampleContainer
+
+class BTreeContainer(SampleContainer, Persistent):
+
+    __implements__ = SampleContainer.__implements__, Persistent.__implements__
+
+    def _Container__newData(self):
+        """Construct an item-data container
+
+        Subclasses should override this if they want different data.
+
+        The value returned is a mapping object that also has get,
+        has_key, keys, items, and values methods.
+        """
+        return OOBTree()


=== Zope3/lib/python/Zope/App/OFS/Container/ContainerTraversable.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+Revision:
+$Id$
+"""
+
+
+from Zope.App.Traversing.ITraversable import ITraversable
+from Zope.App.Traversing.Exceptions import UnexpectedParameters
+from IContainer import IReadContainer
+from Zope.Exceptions import NotFoundError
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+
+_marker = object()
+
+class ContainerTraversable:
+    """Traverses containers via getattr and get.
+    """
+
+    __implements__ = ITraversable
+    __used_for__ = IReadContainer
+
+    def __init__(self, container):
+        self._container = container
+
+
+    def traverse(self, name, parameters, original_name, furtherPath):
+        if parameters:
+            raise UnexpectedParameters(parameters)
+
+        container = self._container
+        
+        v = container.get(name, _marker)
+        if v is _marker:
+            v = getattr(container, name, _marker)
+            if v is _marker:            
+                raise NotFoundError, original_name
+
+        return v
+


=== Zope3/lib/python/Zope/App/OFS/Container/ContainerTraverser.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+    Define view component for folder contents.
+"""
+
+import os
+
+from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
+from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
+from Zope.Publisher.Exceptions import NotFound
+from IContainer import IReadContainer
+from Zope.ComponentArchitecture import queryView
+from Zope.ComponentArchitecture import getDefaultViewName
+
+
+class ContainerTraverser:
+
+    __implements__ = IBrowserPublisher, IXMLRPCPublisher
+    __used_for__ = IReadContainer
+
+    def __init__(self, container, request):
+        self.context = container
+
+    def publishTraverse(self, request, name):
+        c = self.context
+
+        subob = c.get(name, None)
+        if subob is None:
+
+            view = queryView(c, name, request)
+            if view is not None:
+                return view
+
+            raise NotFound(c, name, request)
+        return subob
+
+    def browserDefault(self, request):
+        """
+        """
+        c = self.context
+        view_name = getDefaultViewName(c, request)
+        view_uri = "@@%s" % view_name
+        return c, (view_uri,)
+


=== Zope3/lib/python/Zope/App/OFS/Container/Exceptions.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+    Define adder component for folders.
+"""
+
+class DuplicateIDError(KeyError):
+    pass
+
+class ContainerError(Exception):
+    """An error of a container with one of its components
+    """
+    
+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__
\ No newline at end of file


=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+from Interface import Interface
+from Interface.Common.Mapping import IEnumerableMapping
+
+class IReadContainer(IEnumerableMapping):
+    """Readable content containers
+
+       For all methods that return a sequence of values, the return
+       value is guaranteed to support the read-only semantics of a
+       Python sequence (indexing, slicing, len). The return value is
+       not, however, required to be an actual native sequence type
+       (list or tuple).
+
+       Note that the IReadContainer interface implies a collection of
+       objects that are exposed via various publishing mechanisms.
+       Collections of object that *do not* want to be traversed should
+       not implement this.
+
+       """
+
+class IWriteContainer(Interface):
+    """An interface for the write aspects of a container."""
+
+    def setObject(key, object):
+        """Add the given object to the container under the given key.
+
+        Raises a ValueError if key is an empty string.
+
+        Returns the key used, which might be different than the given key
+        """
+
+    def __delitem__(key):
+        """Delete the keyd object from the container.
+
+        Raises a KeyError if the object is not found.
+
+        """
+
+class IContainer(IReadContainer, IWriteContainer):
+    """Readable and writable content container."""
+
+class IHomogenousContainer(Interface):
+
+    # XXX this needs to be rethought a bit.
+    def isAddable(interfaces):
+        """Test for interface compatability for container and factory
+
+        Tells you whether something that implements the given
+        interfaces may be added to this container.
+
+        The argument may be a single interface, a tuple of interfaces,
+        or None, if the thing you're considering adding declares no
+        interfaces.
+
+        Returns a true value if an object that implements absolutely all
+        of the given interfaces may be added to this container.
+        Otherwise, returns false."""
+


=== Zope3/lib/python/Zope/App/OFS/Container/IContainerLimit.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+  $Id$
+"""
+
+from Interface import Interface
+
+class IReadContainerLimit(Interface):
+
+
+    def getLimit():
+        """Get the maximal amount of possible objects in this container.
+        """
+
+
+    def isLimitReached():
+        """Returns a boolean describing whether the folder reached its maximal
+           amount of objects."""
+
+class IWriteContainerLimit(Interface):
+
+
+    def setLimit(limit):
+        """Set the maximal amount of possible objects in this container.
+        """
+
+class IContainerLimit(IReadContainerLimit, IWriteContainerLimit):
+    """This interface adds a specific functionality to a container by
+       specifying the limiting amount of objects in a container.
+
+       NOTE: This interface expects that the IReadContainer interface.
+    """
+    
+        


=== Zope3/lib/python/Zope/App/OFS/Container/IOrderedContainer.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+  $Id$
+"""
+
+from Interface import Interface
+
+class IReadOrderedContainer(Interface):
+
+
+    def getObjectPosition(id):
+        """Get the position of the object having the id.
+        """
+    
+class IWriteOrderedContainer(Interface):
+
+
+    def moveObjectToPosition(id, position):
+        """Move an object having id to position.
+        """
+        
+
+    def moveObjectsUp(ids):
+        """Move the specified objects (via ids) one field up.
+        """
+
+    
+    def moveObjectsDown(ids):
+        """Move the specified objects (via ids) one field down.
+        """
+
+
+    def moveObjectsToTop(ids):
+        """Move the specified objects (via ids) to the top.
+        """
+
+
+    def moveObjectsToBottom(ids):
+        """Move the specified objects (via ids) to the bottom.
+        """
+
+
+class IOrderedContainer(IReadOrderedContainer, IWriteOrderedContainer):
+    """This interface adds functionality to containers that will allow
+       sorting of the contained items.
+       
+    """


=== Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""
+This module provides a sample container implementation.
+
+This is primarily for testing purposes.
+
+It might be useful as a mix-in for some classes, but many classes will
+need a very different implementation.
+
+Revision information:
+$Id$
+"""
+
+from IContainer import IContainer
+from types import StringTypes
+from Exceptions import UnaddableError
+
+class SampleContainer(object):
+    """Sample container implementation suitable for testing.
+
+    It is not suitable, directly as a base class unless the subclass
+    overrides _Container__newData to return a persistent mapping
+    object.
+    """
+
+    __implements__ =  IContainer
+
+    def __init__(self):
+        self.__data = self._Container__newData()
+
+    def _Container__newData(self):
+        """Construct an item-data container
+
+        Subclasses should override this if they want different data.
+
+        The value returned is a mapping object that also has get,
+        has_key, keys, items, and values methods.
+        """
+        return {}
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.OFS.Container.IContainer
+
+    def keys(self):
+        '''See interface IReadContainer'''
+        return self.__data.keys()
+
+    def __iter__(self):
+        return iter(self.__data.keys())
+
+    def __getitem__(self, key):
+        '''See interface IReadContainer'''
+        return self.__data[key]
+
+    def get(self, key, default=None):
+        '''See interface IReadContainer'''
+        return self.__data.get(key, default)
+
+    def values(self):
+        '''See interface IReadContainer'''
+        return self.__data.values()
+
+    def __len__(self):
+        '''See interface IReadContainer'''
+        return len(self.__data)
+
+    def items(self):
+        '''See interface IReadContainer'''
+        return self.__data.items()
+
+    def __contains__(self, key):
+        '''See interface IReadContainer'''
+        return self.__data.has_key(key)
+
+    has_key = __contains__
+
+    def setObject(self, key, object):
+        '''See interface IWriteContainer'''
+        if type(key) in StringTypes and len(key)==0:
+            raise ValueError("The id cannot be an empty string")
+        self.__data[key] = object
+        return key
+
+    def __delitem__(self, key):
+        '''See interface IWriteContainer'''
+        del self.__data[key]
+
+    #
+    ############################################################


=== Zope3/lib/python/Zope/App/OFS/Container/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+# 
+##############################################################################
+"""Provide generic container support components
+"""
\ No newline at end of file


=== Zope3/lib/python/Zope/App/OFS/Container/container.zcml 1.1 => 1.2 ===
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:browser='http://namespaces.zope.org/browser'
+   xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'
+   xmlns:vfs='http://namespaces.zope.org/vfs'
+   xmlns:security='http://namespaces.zope.org/security'
+>
+
+  <browser:view
+      name="_traverse" 
+      for=".IContainer.IReadContainer"
+      factory=".ContainerTraverser." />
+
+  <xmlrpc:view
+      name="_traverse" 
+      for=".IContainer.IReadContainer."
+      factory=".ContainerTraverser." />
+
+  <adapter factory=".ContainerTraversable."
+           provides="Zope.App.Traversing.ITraversable."
+           for=".IContainer.IReadContainer." />
+
+  <browser:view name="_traverse" 
+      for=".IContainer."
+      factory=".ContainerTraverser." />
+
+  <xmlrpc:view name="_traverse" 
+      for=".IContainer."
+      factory=".ContainerTraverser." />
+
+  <vfs:view name="_traverse" 
+      for=".IContainer."
+      factory=".ContainerTraverser." />
+
+  <adapter factory=".ContainerTraversable."
+           provides="Zope.App.Traversing.ITraversable."
+           for=".IContainer.IReadContainer." />
+
+
+  <include package=".Find" file="find.zcml" />
+
+</zopeConfigure>