[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Folder - Folder.py:1.1.2.1

Christian Theune ct@gocept.com
Sat, 18 May 2002 06:15:51 -0400


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

Added Files:
      Tag: ctheune-foldermove-branch
	Folder.py 
Log Message:
Renamed Folder.py to ../Content/Folder//Folder.py

=== Added File Zope3/lib/python/Zope/App/OFS/Content/Folder/Folder.py ===
##############################################################################
#
# 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 Zope.App.OFS.Container.IContainer import IContainer
from Zope.App.OFS.Memento.IAttributeMementoStorable \
     import IAttributeMementoStorable
import Persistence
from Persistence.BTrees.OOBTree import OOBTree
from Zope.ComponentArchitecture.ServiceManagerContainer \
     import ServiceManagerContainer

from Zope.ComponentArchitecture.IServiceManagerContainer import \
     IServiceManagerContainer
from types import StringTypes

from Zope.App.OFS.Container.Exceptions import UnaddableError

class IFolder(IContainer, IServiceManagerContainer):
    """The standard Zope Folder object interface."""

class Folder(Persistence.Persistent, ServiceManagerContainer):
    """The standard Zope Folder implementation."""

    __implements__ = (
        IFolder,
        IAttributeMementoStorable,
        )

    def __init__(self):
        self.data = OOBTree()

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

    def objectValues(self):
        """Return a sequence-like object containing the objects that
           appear in the folder.
        """
        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 folder.
        """
        return self.data.items()

    def getObject(self, name, default=KeyError):
        """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.
        """
        object = self.data.get(name, default)
        if object is KeyError:
            raise KeyError, name
        return object

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

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

    def setObject(self, name, object):
        """Add the given object to the folder under the given name."""
        if type(name) in StringTypes and len(name)==0:
            raise ValueError
        if not self.isAddable(getattr(object,'__implements__', None)):
            raise UnaddableError (self, object, name)
        self.data[name] = object

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

    def isAddable(self, interfaces):
        return 1