Commit ab6b6941 authored by 's avatar

- fixed TypeError handling in unrestrictedTraverse

parent 6d7f64a4
...@@ -8,6 +8,8 @@ http://docs.zope.org/zope2/releases/. ...@@ -8,6 +8,8 @@ http://docs.zope.org/zope2/releases/.
2.13.16 (unreleased) 2.13.16 (unreleased)
-------------------- --------------------
- OFS: Fixed TypeError handling in unrestrictedTraverse.
- Updated distributions: - Updated distributions:
- AccessControl = 2.13.8 - AccessControl = 2.13.8
......
...@@ -260,9 +260,10 @@ class Traversable: ...@@ -260,9 +260,10 @@ class Traversable:
if isinstance(next, NullResource): if isinstance(next, NullResource):
resource = next resource = next
raise KeyError(name) raise KeyError(name)
except AttributeError: except (AttributeError, TypeError):
# Raise NotFound for easier debugging # Raise NotFound for easier debugging
# instead of AttributeError: __getitem__ # instead of AttributeError: __getitem__
# or TypeError: not subscriptable
raise NotFound(name) raise NotFound(name)
if restricted and not validate( if restricted and not validate(
obj, obj, None, next): obj, obj, None, next):
......
...@@ -402,6 +402,20 @@ class TestTraverse( unittest.TestCase ): ...@@ -402,6 +402,20 @@ class TestTraverse( unittest.TestCase ):
self.assertEqual( self.assertEqual(
self.root.folder1.restrictedTraverse('stuff', 42), 42) 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): def testDefaultValueWhenNotFound(self):
# Test that traversing to a non-existent object returns # Test that traversing to a non-existent object returns
# the default when provided # 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