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
cd5a3f35
Commit
cd5a3f35
authored
Apr 24, 2007
by
Martijn Pieters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
To aid debugging, generate the facade with the same name as the original callable
parent
01666dcd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
lib/python/AccessControl/requestmethod.py
lib/python/AccessControl/requestmethod.py
+6
-5
lib/python/AccessControl/requestmethod.txt
lib/python/AccessControl/requestmethod.txt
+6
-2
No files found.
lib/python/AccessControl/requestmethod.py
View file @
cd5a3f35
...
...
@@ -17,7 +17,7 @@ from zope.publisher.interfaces.browser import IBrowserRequest
_default
=
[]
def
_buildFacade
(
spec
,
docstring
):
def
_buildFacade
(
name
,
spec
,
docstring
):
"""Build a facade function, matching the decorated method in signature.
Note that defaults are replaced by _default, and _curried will reconstruct
...
...
@@ -26,8 +26,8 @@ def _buildFacade(spec, docstring):
"""
args
=
inspect
.
formatargspec
(
formatvalue
=
lambda
v
:
'=_default'
,
*
spec
)
callargs
=
inspect
.
formatargspec
(
formatvalue
=
lambda
v
:
''
,
*
spec
)
return
'def
_facade
%s:
\
n
"""%s"""
\
n
return _curried%s'
%
(
args
,
docstring
,
callargs
)
return
'def
%s
%s:
\
n
"""%s"""
\
n
return _curried%s'
%
(
name
,
args
,
docstring
,
callargs
)
def
requestmethod
(
*
methods
):
"""Create a request method specific decorator"""
...
...
@@ -70,9 +70,10 @@ def requestmethod(*methods):
return
callable
(
*
args
,
**
kw
)
# Build a facade, with a reference to our locally-scoped _curried
name
=
callable
.
__name__
facade_globs
=
dict
(
_curried
=
_curried
,
_default
=
_default
)
exec
_buildFacade
(
spec
,
callable
.
__doc__
)
in
facade_globs
return
facade_globs
[
'_facade'
]
exec
_buildFacade
(
name
,
spec
,
callable
.
__doc__
)
in
facade_globs
return
facade_globs
[
name
]
return
_methodtest
...
...
lib/python/AccessControl/requestmethod.txt
View file @
cd5a3f35
...
...
@@ -57,12 +57,16 @@ original closely, and keyword parameter defaults must be preserved::
>>> import inspect
>>> mutabledefault = dict()
>>> @requestmethod('POST')
... def foo(bar, baz=mutabledefault, egg=mutabledefault, REQUEST=None, *
*kw
):
... def foo(bar, baz=mutabledefault, egg=mutabledefault, REQUEST=None, *
args
):
... return bar, baz is mutabledefault, egg is None, REQUEST
>>> inspect.getargspec(foo)[:3]
(['bar', 'baz', 'egg', 'REQUEST'],
None, 'kw'
)
(['bar', 'baz', 'egg', 'REQUEST'],
'args', None
)
>>> foo('spam', egg=None)
('spam', True, True, None)
>>> foo(monty='python')
Traceback (most recent call last):
...
TypeError: foo() got an unexpected keyword argument 'monty'
The requestmethod decorator factory can be used for any request method, simply
pass in the desired request method::
...
...
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