Commit a4bd7649 authored by 's avatar

- fixed TypeError handling in unrestrictedTraverse

parent b70b086b
......@@ -284,9 +284,10 @@ class Traversable:
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):
......
......@@ -402,6 +402,20 @@ class TestTraverse( unittest.TestCase ):
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment