Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
2aa5f2cc
Commit
2aa5f2cc
authored
Apr 24, 2010
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fixed handling of errors in 'traverseName'
parent
1404f1da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
src/ZPublisher/BaseRequest.py
src/ZPublisher/BaseRequest.py
+5
-5
src/ZPublisher/tests/testBaseRequest.py
src/ZPublisher/tests/testBaseRequest.py
+25
-3
No files found.
src/ZPublisher/BaseRequest.py
View file @
2aa5f2cc
...
...
@@ -26,6 +26,7 @@ from zope.event import notify
from
zope.publisher.defaultview
import
queryDefaultViewName
from
zope.publisher.interfaces
import
EndRequestEvent
from
zope.publisher.interfaces
import
IPublishTraverse
from
zope.publisher.interfaces
import
NotFound
as
ztkNotFound
from
zope.publisher.interfaces.browser
import
IBrowserPublisher
from
zope.traversing.interfaces
import
TraversalError
from
zope.traversing.namespace
import
nsParse
,
namespaceLookup
...
...
@@ -312,7 +313,7 @@ class BaseRequest:
__repr__
=
__str__
# Original version: see zope.traversing.publicationtraverse
def
traverseName
(
self
,
ob
,
name
):
if
name
and
name
[:
1
]
in
'@+'
:
# Process URI segment parameters.
...
...
@@ -321,7 +322,7 @@ class BaseRequest:
try
:
ob2
=
namespaceLookup
(
ns
,
nm
,
ob
,
self
)
except
TraversalError
:
raise
KeyError
(
ob
,
name
)
raise
ztkNotFound
(
ob
,
name
)
if
IAcquirer
.
providedBy
(
ob2
):
ob2
=
ob2
.
__of__
(
ob
)
...
...
@@ -343,7 +344,6 @@ class BaseRequest:
return
ob2
def
traverse
(
self
,
path
,
response
=
None
,
validated_hook
=
None
):
"""Traverse the object space
...
...
@@ -506,7 +506,8 @@ class BaseRequest:
object
,
check_name
,
subobject
,
self
.
roles
)
object
=
subobject
except
(
KeyError
,
AttributeError
):
# traverseName() might raise ZTK's NotFound
except
(
KeyError
,
AttributeError
,
ztkNotFound
):
if
response
.
debug_mode
:
return
response
.
debugError
(
"Cannot locate object at: %s"
%
URL
)
...
...
@@ -517,7 +518,6 @@ class BaseRequest:
return
response
.
debugError
(
e
.
args
)
else
:
return
response
.
forbiddenError
(
entry_name
)
parents
.
append
(
object
)
...
...
src/ZPublisher/tests/testBaseRequest.py
View file @
2aa5f2cc
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
:
def
_makeOne
(
self
,
root
):
...
...
@@ -138,6 +153,7 @@ class BaseRequest_factory:
return
'unpublishable'
return
DummyObjectWithEmptyDocstring
()
class
TestBaseRequest
(
unittest
.
TestCase
,
BaseRequest_factory
):
def
_getTargetClass
(
self
):
...
...
@@ -372,12 +388,18 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def
test_traverse_unsubscriptable
(
self
):
# See https://bugs.launchpad.net/bugs/213311
from
ZPublisher
import
NotFound
class
_Object
(
object
):
pass
root
=
_Object
()
r
=
self
.
_makeOne
(
None
)
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment