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
d47d90f2
Commit
d47d90f2
authored
Apr 03, 2007
by
Martijn Pieters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend the requestmethod decorator factory to allow multiple request methods
parent
5db07830
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
lib/python/AccessControl/requestmethod.py
lib/python/AccessControl/requestmethod.py
+10
-5
lib/python/AccessControl/requestmethod.txt
lib/python/AccessControl/requestmethod.txt
+12
-0
No files found.
lib/python/AccessControl/requestmethod.py
View file @
d47d90f2
...
...
@@ -27,12 +27,17 @@ def _buildFacade(spec, docstring):
return
'def _facade%s:
\
n
"""%s"""
\
n
return _curried%s'
%
(
args
,
docstring
,
callargs
)
def
requestmethod
(
method
):
def
requestmethod
(
*
methods
):
"""Create a request method specific decorator"""
method
=
method
.
upper
()
methods
=
map
(
lambda
m
:
m
.
upper
(),
methods
)
if
len
(
methods
)
>
1
:
methodsstr
=
', '
.
join
(
methods
[:
-
1
])
methodsstr
+=
' or '
+
methods
[
-
1
]
else
:
methodsstr
=
methods
[
0
]
def
_methodtest
(
callable
):
"""Only allow callable when request method is %s."""
%
method
"""Only allow callable when request method is %s."""
%
method
sstr
spec
=
inspect
.
getargspec
(
callable
)
args
,
defaults
=
spec
[
0
],
spec
[
3
]
try
:
...
...
@@ -51,8 +56,8 @@ def requestmethod(method):
request
=
args
[
r_index
]
if
IBrowserRequest
.
providedBy
(
request
):
if
request
.
method
!=
method
:
raise
Forbidden
(
'Request must be %s'
%
method
)
if
request
.
method
not
in
methods
:
raise
Forbidden
(
'Request must be %s'
%
method
sstr
)
# Reconstruct keyword arguments
if
defaults
is
not
None
:
...
...
lib/python/AccessControl/requestmethod.txt
View file @
d47d90f2
...
...
@@ -74,3 +74,15 @@ pass in the desired request method::
Traceback (most recent call last):
...
Forbidden: Request must be PUT
You can pass in multiple request methods allow access by any of them::
>>> @requestmethod('GET', 'HEAD', 'PROPFIND')
... def foo(bar, REQUEST=None):
... return bar
>>> foo('spam', GET)
'spam'
>>> foo('spam', POST)
Traceback (most recent call last):
...
Forbidden: Request must be GET, HEAD or PROPFIND
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