[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - ContainerTraversable.py:1.1.2.6
Jim Fulton
jim@zope.com
Thu, 23 May 2002 14:01:40 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/OFS/Container
Modified Files:
Tag: Zope-3x-branch
ContainerTraversable.py
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)
That lead me to:
- Massive traversal refactoring.
Namespace handling is now centralized in Zope.App.Traversing.
- ZPT refactoring, including some renaming that touches pretty much everything. :)
- The application specific ZPT support was moved into
Zope.App.PageTemplate.
- To get page template files (for use in views):
from Zope.App.PageTemplate import ViewPageTemplateFile
- Fixed up security so that ZPT expressions only have access to
safe builtins and so that modules namespace does imports safely.
- Got ZPTPage working!
- renaming url to absolute_url and got absolute_url to work in paths.
- Cleaned up the (as yet unused) RestrictedInterpreter module in
Zope.Security. In particular, changed to use a separate
RestrictedBuiltins module.
=== Zope3/lib/python/Zope/App/OFS/Container/ContainerTraversable.py 1.1.2.5 => 1.1.2.6 ===
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
@@ -43,42 +44,18 @@
def __init__(self, container):
self._container = container
- def traverse(self, name, furtherPath):
+ def traverse(self, name, parameters, original_name, furtherPath):
+ if parameters:
+ raise UnexpectedParameters(parameters)
+
container = self._container
+
+ # self is just a marker for the rest of this method.
- # keep original name to return in a NotFoundError
- original_name = name
-
- if ';' in original_name:
- # explicit traversal to a namespace
- # containers know about "method" and "content"
-
- name,namespace = original_name.split(';', 1)
- if namespace.startswith("ns="): # XXX not very graceful; temporary
- namespace=namespace[3:]
-
- # XXX take out the etc if you take out the Services below
- if namespace not in ('method', 'content', 'etc'):
- raise NotFoundError, 'unrecognised namespace "%s" in "%s"' \
- % (namespace, original_name)
- else:
- # traversal with no namespace given
- # containers try methods, then if no method if found,
- # their contents.
-
- namespace = None
-
- if namespace in (None, 'method') and hasattr(container, name):
- return getattr(container, name)
-
- if namespace in (None, 'content') and container.hasObject(name):
- return container.getObject(name)
-
- # XXX probably shouldn't be here
- if namespace in (None, 'etc') and name=='Services':
- try:
- return container.getServiceManager()
- except AttributeError, ComponentLookupError:
- pass # raise below
-
- raise NotFoundError, original_name
+ v = container.getObject(name, self)
+ if v is self:
+ v = getattr(container, name, self)
+ if v is self:
+ raise NotFoundError, original_name
+
+ return v