[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing - DefaultTraversable.py:1.1.2.3
Shane Hathaway
shane@cvs.zope.org
Wed, 13 Mar 2002 23:11:12 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing
In directory cvs.zope.org:/tmp/cvs-serv15136
Modified Files:
Tag: Zope-3x-branch
DefaultTraversable.py
Log Message:
Avoided swallowing exceptions, using a check for the __getitem__ attribute
before looking up items of an object. In Python 2.2+ this should work
reliably.
=== Zope3/lib/python/Zope/App/Traversing/DefaultTraversable.py 1.1.2.2 => 1.1.2.3 ===
class DefaultTraversable:
- """Traverses objects via attribute and dictionary lookup"""
+ """Traverses objects via attribute and item lookup"""
__implements__ = ITraversable
@@ -19,11 +19,13 @@
self._subject = subject
def traverse(self, name, furtherPath):
- if hasattr(self._subject, name):
- return getattr(self._subject, name)
+ subject = self._subject
+ if hasattr(subject, name):
+ return getattr(subject, name)
else:
- try:
+ if hasattr(subject, '__getitem__'):
+ # Let exceptions propagate.
return self._subject[name]
- except (KeyError, IndexError, TypeError, AttributeError):
+ else:
raise NotFoundError, name