[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - ContainerTraversable.py:1.1.2.1 ContainerTraverser.py:1.1.2.1 IContainer.py:1.1.2.1 SampleContainer.py:1.1.2.3
Jim Fulton
jim@zope.com
Mon, 4 Mar 2002 16:43:45 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container
In directory cvs.zope.org:/tmp/cvs-serv23162/Container
Modified Files:
Tag: Zope-3x-branch
SampleContainer.py
Added Files:
Tag: Zope-3x-branch
ContainerTraversable.py ContainerTraverser.py IContainer.py
Log Message:
Finished refactoring container manageemnt by moving IContainer and
ContainerTraverser down to Container.
=== Added File Zope3/lib/python/Zope/App/OFS/Container/ContainerTraversable.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.Traversing.ITraversable import ITraversable
from IContainer import IReadContainer
from Zope.Exceptions import NotFoundError
class ContainerTraversable:
"""Traverses containers via getObject"""
__implements__ = ITraversable
__used_for__ = IReadContainer
def __init__(self, container):
self._container = container
def traverse(self, name, furtherPath):
next = self._container.getObject(name, None)
if next is None:
raise NotFoundError, name
return next
=== Added File Zope3/lib/python/Zope/App/OFS/Container/ContainerTraverser.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.Exceptions import NotFound
from IContainer import IReadContainer
from Zope.ComponentArchitecture import getRequestView
from Zope.ComponentArchitecture import getRequestDefaultViewName
class ContainerTraverser:
__implements__ = IBrowserPublisher
__used_for__ = IReadContainer
def __init__(self, c):
self._c = c
def browser_traverse(self, request, name):
c = self._c
if name.endswith(';view'):
p = getRequestView(c, name[:-5], request)
if p is None:
raise NotFound(c, name, request)
else:
return p
subob = c.getObject(name, None)
if subob is None:
raise NotFound(c, name, request)
return subob
def browser_default(self, request):
"""
"""
c = self._c
view_name = getRequestDefaultViewName(c, request)
view_uri = "%s;view" % view_name
return c, (view_uri,)
=== Added File Zope3/lib/python/Zope/App/OFS/Container/IContainer.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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
_RAISE_KEYERROR = []
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).
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."""
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=_RAISE_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."""
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(name, object):
"""Add the given object to the container under the given name."""
def delObject(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."""
=== Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py 1.1.2.2 => 1.1.2.3 ===
"""
-from Zope.App.OFS.IContainer import IContainer
+from IContainer import IContainer
_marker = object()
@@ -52,7 +52,7 @@
############################################################
# Implementation methods for interface
- # Zope.App.OFS.IContainer
+ # Zope.App.OFS.Container.IContainer
def objectIds(self):
'''See interface IReadContainer'''