[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - ContainerTraverser.py:1.3 IContainer.py:1.5 container.zcml:1.3
Jim Fulton
jim@zope.com
Tue, 11 Jun 2002 19:12:35 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container
In directory cvs.zope.org:/tmp/cvs-serv9277/lib/python/Zope/App/OFS/Container
Modified Files:
ContainerTraverser.py IContainer.py container.zcml
Log Message:
Refactored interfaces defined in IContainer. In particular, defined an
IItemContainer that *just* implements __getitem__ and registered a
minimal traverser for it that:
- first tries to get an item, and, if that fails
- falls back to a view lookup.
=== Zope3/lib/python/Zope/App/OFS/Container/ContainerTraverser.py 1.2 => 1.3 ===
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from Zope.Publisher.Exceptions import NotFound
-from IContainer import IReadContainer
+from IContainer import IReadContainer, IItemContainer
from Zope.ComponentArchitecture import queryView
from Zope.ComponentArchitecture import getDefaultViewName
@@ -44,13 +44,29 @@
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,)
+
+class ItemTraverser(ContainerTraverser):
+
+ __used_for__ = IItemContainer
+
+ def publishTraverse(self, request, name):
+ context = self.context
+
+ try:
+ return context[name]
+
+ except KeyError:
+ view = queryView(context, name, request)
+ if view is not None:
+ return view
+
+ raise NotFound(context, name, request)
=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.4 => 1.5 ===
#
##############################################################################
+"""
+
+"""
+
+
from Interface import Interface
-from Interface.Common.Mapping import IEnumerableMapping
+from Interface.Common.Mapping import IReadMapping, IEnumerableMapping
-class IReadContainer(IEnumerableMapping):
- """Readable content containers
+class IItemContainer(Interface):
- 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 __getitem__(key):
+ """Return the content for the given key
+
+ Raises KeyError if the content can't be found.
+ """
+
+class ISimpleReadContainer(IItemContainer, IReadMapping):
+ """Readable content containers
+ """
- """
+class IReadContainer(ISimpleReadContainer, IEnumerableMapping):
+ """Readable containers that can be enumerated.
+ """
class IWriteContainer(Interface):
"""An interface for the write aspects of a container."""
=== Zope3/lib/python/Zope/App/OFS/Container/container.zcml 1.2 => 1.3 ===
<browser:view
name="_traverse"
+ for=".IContainer.IItemContainer."
+ factory=".ContainerTraverser.ItemTraverser" />
+
+ <browser:view
+ name="_traverse"
for=".IContainer.IReadContainer"
factory=".ContainerTraverser." />
@@ -16,21 +21,13 @@
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." />
<adapter factory=".ContainerTraversable."
provides="Zope.App.Traversing.ITraversable."