Commit 540ee999 authored by 's avatar

- fixed handling of errors in 'traverseName'

parent 4c095336
...@@ -15,6 +15,11 @@ Features Added ...@@ -15,6 +15,11 @@ Features Added
- ZODB3 = 3.9.5 - ZODB3 = 3.9.5
Bugs Fixed
++++++++++
- BaseRequest: Fixed handling of errors in 'traverseName'.
2.12.5 (2010-04-24) 2.12.5 (2010-04-24)
------------------- -------------------
......
...@@ -26,6 +26,7 @@ from zope.event import notify ...@@ -26,6 +26,7 @@ from zope.event import notify
from zope.app.publication.interfaces import EndRequestEvent from zope.app.publication.interfaces import EndRequestEvent
from zope.publisher.defaultview import queryDefaultViewName from zope.publisher.defaultview import queryDefaultViewName
from zope.publisher.interfaces import IPublishTraverse from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound as ztkNotFound
from zope.publisher.interfaces.browser import IBrowserPublisher from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.traversing.interfaces import TraversalError from zope.traversing.interfaces import TraversalError
from zope.traversing.namespace import nsParse, namespaceLookup from zope.traversing.namespace import nsParse, namespaceLookup
...@@ -312,7 +313,7 @@ class BaseRequest: ...@@ -312,7 +313,7 @@ class BaseRequest:
__repr__=__str__ __repr__=__str__
# Original version: see zope.traversing.publicationtraverse
def traverseName(self, ob, name): def traverseName(self, ob, name):
if name and name[:1] in '@+': if name and name[:1] in '@+':
# Process URI segment parameters. # Process URI segment parameters.
...@@ -321,7 +322,7 @@ class BaseRequest: ...@@ -321,7 +322,7 @@ class BaseRequest:
try: try:
ob2 = namespaceLookup(ns, nm, ob, self) ob2 = namespaceLookup(ns, nm, ob, self)
except TraversalError: except TraversalError:
raise KeyError(ob, name) raise ztkNotFound(ob, name)
if IAcquirer.providedBy(ob2): if IAcquirer.providedBy(ob2):
ob2 = ob2.__of__(ob) ob2 = ob2.__of__(ob)
...@@ -343,7 +344,6 @@ class BaseRequest: ...@@ -343,7 +344,6 @@ class BaseRequest:
return ob2 return ob2
def traverse(self, path, response=None, validated_hook=None): def traverse(self, path, response=None, validated_hook=None):
"""Traverse the object space """Traverse the object space
...@@ -506,7 +506,8 @@ class BaseRequest: ...@@ -506,7 +506,8 @@ class BaseRequest:
object, check_name, subobject, object, check_name, subobject,
self.roles) self.roles)
object = subobject object = subobject
except (KeyError, AttributeError): # traverseName() might raise ZTK's NotFound
except (KeyError, AttributeError, ztkNotFound):
if response.debug_mode: if response.debug_mode:
return response.debugError( return response.debugError(
"Cannot locate object at: %s" % URL) "Cannot locate object at: %s" % URL)
...@@ -517,7 +518,6 @@ class BaseRequest: ...@@ -517,7 +518,6 @@ class BaseRequest:
return response.debugError(e.args) return response.debugError(e.args)
else: else:
return response.forbiddenError(entry_name) return response.forbiddenError(entry_name)
parents.append(object) parents.append(object)
...@@ -711,8 +711,7 @@ def old_validation(groups, request, auth, ...@@ -711,8 +711,7 @@ def old_validation(groups, request, auth,
# types during publishing, we ensure the same publishing rules in # types during publishing, we ensure the same publishing rules in
# both versions. The downside is that this needs to be extended as # both versions. The downside is that this needs to be extended as
# new built-in types are added and future Python versions are # new built-in types are added and future Python versions are
# supported. That happens rarely enough that hopefully we'll be on # supported.
# Zope 3 by then :)
import types import types
......
import unittest import unittest
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound as ztkNotFound
class DummyTraverser(object):
implements(IPublishTraverse)
def publishTraverse(self, request, name):
if name == 'dummy':
return 'dummy object'
raise ztkNotFound(self, name)
class BaseRequest_factory: class BaseRequest_factory:
def _makeOne(self, root): def _makeOne(self, root):
...@@ -138,6 +153,7 @@ class BaseRequest_factory: ...@@ -138,6 +153,7 @@ class BaseRequest_factory:
return 'unpublishable' return 'unpublishable'
return DummyObjectWithEmptyDocstring() return DummyObjectWithEmptyDocstring()
class TestBaseRequest(unittest.TestCase, BaseRequest_factory): class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def _getTargetClass(self): def _getTargetClass(self):
...@@ -372,12 +388,18 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory): ...@@ -372,12 +388,18 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def test_traverse_unsubscriptable(self): def test_traverse_unsubscriptable(self):
# See https://bugs.launchpad.net/bugs/213311 # See https://bugs.launchpad.net/bugs/213311
from ZPublisher import NotFound from ZPublisher import NotFound
class _Object(object):
pass
root = _Object()
r = self._makeOne(None) r = self._makeOne(None)
self.assertRaises(NotFound, r.traverse, 'not_found') self.assertRaises(NotFound, r.traverse, 'not_found')
def test_traverse_publishTraverse(self):
r = self._makeOne(DummyTraverser())
self.assertEqual(r.traverse('dummy'), 'dummy object')
def test_traverse_publishTraverse_error(self):
from ZPublisher import NotFound
r = self._makeOne(DummyTraverser())
self.assertRaises(NotFound, r.traverse, 'not_found')
class TestBaseRequestZope3Views(unittest.TestCase, BaseRequest_factory): class TestBaseRequestZope3Views(unittest.TestCase, BaseRequest_factory):
......
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