Skip to content

Commit

Permalink
- fixed TypeError handling in unrestrictedTraverse
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Jul 10, 2012
1 parent b70b086 commit a4bd764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/OFS/Traversable.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,10 @@ def unrestrictedTraverse(self, path, default=_marker, restricted=False):
if isinstance(next, NullResource):
resource = next
raise KeyError(name)
except AttributeError:
except (AttributeError, TypeError):
# Raise NotFound for easier debugging
# instead of AttributeError: __getitem__
# or TypeError: not subscriptable
raise NotFound(name)
if restricted and not validate(
obj, obj, None, next):
Expand Down
14 changes: 14 additions & 0 deletions src/OFS/tests/testTraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,20 @@ def testDefaultValueWhenUnathorized(self):
self.assertEqual(
self.root.folder1.restrictedTraverse('stuff', 42), 42)

def testNotFoundIsRaised(self):
from OFS.SimpleItem import SimpleItem
from zExceptions import NotFound
from operator import getitem
self.folder1._setObject('foo', SimpleItem('foo'))
self.assertRaises(AttributeError, getitem, self.folder1.foo,
'doesntexist')
self.assertRaises(NotFound, self.folder1.unrestrictedTraverse,
'foo/doesntexist')
self.assertRaises(TypeError, getitem,
self.folder1.foo.isPrincipiaFolderish, 'doesntexist')
self.assertRaises(NotFound, self.folder1.unrestrictedTraverse,
'foo/isPrincipiaFolderish/doesntexist')

def testDefaultValueWhenNotFound(self):
# Test that traversing to a non-existent object returns
# the default when provided
Expand Down

0 comments on commit a4bd764

Please sign in to comment.