[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS - Container.py:1.1.2.1 IContainer.py:1.1.2.1 __init__.py:1.1.2.1

Brian Lloyd brian@digicool.com
Fri, 16 Nov 2001 16:15:25 -0500


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

Added Files:
      Tag: Zope-3x-branch
	Container.py IContainer.py __init__.py 
Log Message:
Added container interfaces and standard container


=== Added File Zope3/lib/python/Zope/App/OFS/Container.py ===
from IContainer import IContainer


class Container:
    """The default standard container implementation."""

    __implements__ = IContainer

    def __init__(self):
        # XXX - fix this to use a btree when persistence is online.
        self.data = {}

    def objectIds(self):
        """Return a sequence-like object containing the names of the
           objects that appear in the container."""
        return self.data.keys()

    def objectValues(self):
        """Return a sequence-like object containing the objects that
           appear in the container."""
        return self.data.values()

    def objectItems(self):
        """Return a sequence-like object containing tuples of the form
           (name, object) for the objects that appear in the container."""
        return self.data.items()

    def getObject(self, name, default=None):
        """Return the named object of the container, or the value of the
           default if given. If no default is given and the named object
           is not found, None is returned."""
        return self.data.get(name, default)

    def hasObject(self, name):
        """Return true if the named object appears in the container."""
        return self.data.has_key(name)

    def objectCount(self):
        """Return the number of objects in the container."""
        return len(self.data)

    def setObject(self, name, object):
        """Add the given object to the container under the given name."""
        self.data[name] = object

    def delObject(self, name):
        """Delete the named object from the container. Raises a KeyError
           if the object is not found."""
        del self.data[name]



=== Added File Zope3/lib/python/Zope/App/OFS/IContainer.py ===
from Interface import Interface


class IReadContainer(Interface):
    """An interface for the read aspects of a container. 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)."""

    def objectIds():
        """Return a sequence-like object containing the names of the
           objects that appear in the container."""

    def objectValues():
        """Return a sequence-like object containing the objects that
           appear in the container."""

    def objectItems():
        """Return a sequence-like object containing tuples of the form
           (name, object) for the objects that appear in the container."""

    def getObject(name, default=None):
        """Return the named object, or the value of the default argument
           if given and the named object is not found. If no default is
           given and the object is not found a KeyError is raised."""

    def hasObject(name):
        """Return true if the named object appears in the container."""

    def objectCount():
        """Return the number of objects in the container."""


class IWriteContainer(Interface):
    """An interface for the write aspects of a container."""

    def setObject(self, name, object):
        """Add the given object to the container under the given name."""

    def delObject(self, name):
        """Delete the named object from the container. Raises a KeyError
           if the object is not found."""


class IContainer(IReadContainer, IWriteContainer):
    """The interface for working with a readable and writable container."""
    






=== Added File Zope3/lib/python/Zope/App/OFS/__init__.py ===
"""Zope OFS (object file system) package."""