[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing - Traverser.py:1.1.2.7
Shane Hathaway
shane@cvs.zope.org
Wed, 13 Mar 2002 23:14:26 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing
In directory cvs.zope.org:/tmp/cvs-serv16296
Modified Files:
Tag: Zope-3x-branch
Traverser.py
Log Message:
- Report a better exception when no ITraversable is available.
- Updated license and restored whitespace. Code needs room to breathe. :-)
=== Zope3/lib/python/Zope/App/Traversing/Traverser.py 1.1.2.6 => 1.1.2.7 ===
+# Copyright (c) 2001, 2002 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.
@@ -6,6 +7,10 @@
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
+"""Default implementation of ITraverser.
+
+$Id$
+"""
from ITraverser import ITraverser
from ITraversable import ITraversable
@@ -25,7 +30,7 @@
yield w
w = wrapper.getcontext(w)
-_marker = []
+_marker = object()
class Traverser:
"""Provide traverse features"""
@@ -41,7 +46,8 @@
def getPhysicalRoot(self):
# Loop over all wrappers until the last one, which is the root.
- for w in WrapperChain(self._wrapper): pass
+ for w in WrapperChain(self._wrapper):
+ pass
return w
def getPhysicalPath(self):
@@ -49,12 +55,14 @@
for w in WrapperChain(self._wrapper):
d = wrapper.getdict(w)
- if d: path.insert(0, d['name'])
+ if d:
+ path.insert(0, d['name'])
return tuple(path)
def unrestrictedTraverse(self, path, default=_marker, restricted=0):
- if not path: return self._wrapper
+ if not path:
+ return self._wrapper
if isinstance(path, StringTypes):
path = path.split('/')
@@ -74,7 +82,8 @@
# Start at the root
pop()
curr = self.getPhysicalRoot()
- if restricted: validate(None, curr)
+ if restricted:
+ validate(None, curr)
try:
while path:
@@ -85,23 +94,24 @@
if name == '..':
curr = wrapper.getcontext(curr) or curr
- if restricted: validate(None, curr)
+ if restricted:
+ validate(None, curr)
continue
traversable = getAdapter(curr, ITraversable, None)
if traversable is None:
- # Cannot be traversed, so we cannot find the next name
- raise NotFoundError, name
+ raise NotFoundError, 'No traversable adapter found'
- else:
- next = traversable.traverse(name, path)
- curr = wrapper.Wrapper(next, curr, name=name)
- if restricted: validate(name, curr)
+ next = traversable.traverse(name, path)
+ curr = wrapper.Wrapper(next, curr, name=name)
+ if restricted:
+ validate(name, curr)
return curr
except:
- if default == _marker: raise
+ if default == _marker:
+ raise
return default
def restrictedTraverse(self, path, default=_marker):