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
04be2c1c
Commit
04be2c1c
authored
Apr 20, 2007
by
Martijn Pieters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge default value fix from trunk
parent
0dc86d01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
lib/python/AccessControl/requestmethod.py
lib/python/AccessControl/requestmethod.py
+6
-5
lib/python/AccessControl/requestmethod.txt
lib/python/AccessControl/requestmethod.txt
+5
-5
No files found.
lib/python/AccessControl/requestmethod.py
View file @
04be2c1c
...
...
@@ -15,14 +15,16 @@ import inspect
from
zExceptions
import
Forbidden
from
ZPublisher.HTTPRequest
import
HTTPRequest
_default
=
[]
def
_buildFacade
(
spec
,
docstring
):
"""Build a facade function, matching the decorated method in signature.
Note that defaults are replaced by
None
, and _curried will reconstruct
Note that defaults are replaced by
_default
, and _curried will reconstruct
these to preserve mutable defaults.
"""
args
=
inspect
.
formatargspec
(
formatvalue
=
lambda
v
:
'=
None
'
,
*
spec
)
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
)
...
...
@@ -46,7 +48,6 @@ def postonly(callable):
if
len
(
args
)
>
r_index
:
request
=
args
[
r_index
]
if
isinstance
(
request
,
HTTPRequest
):
if
request
.
get
(
'REQUEST_METHOD'
,
'GET'
).
upper
()
!=
'POST'
:
raise
Forbidden
(
'Request must be POST'
)
...
...
@@ -55,7 +56,7 @@ def postonly(callable):
if
defaults
is
not
None
:
args
,
kwparams
=
args
[:
arglen
],
args
[
arglen
:]
for
positional
,
(
key
,
default
)
in
zip
(
kwparams
,
defaults
):
if
positional
is
None
:
if
positional
is
_default
:
kw
[
key
]
=
default
else
:
kw
[
key
]
=
positional
...
...
@@ -63,7 +64,7 @@ def postonly(callable):
return
callable
(
*
args
,
**
kw
)
# Build a facade, with a reference to our locally-scoped _curried
facade_globs
=
dict
(
_curried
=
_curried
)
facade_globs
=
dict
(
_curried
=
_curried
,
_default
=
_default
)
exec
_buildFacade
(
spec
,
callable
.
__doc__
)
in
facade_globs
return
facade_globs
[
'_facade'
]
...
...
lib/python/AccessControl/requestmethod.txt
View file @
04be2c1c
...
...
@@ -61,9 +61,9 @@ original closely, and keyword parameter defaults must be preserved::
>>> import inspect
>>> mutabledefault = dict()
>>> @postonly
... def foo(bar, baz=mutabledefault, REQUEST=None, **kw):
... return bar, baz is mutabledefault, REQUEST
... def foo(bar, baz=mutabledefault,
egg=mutabledefault,
REQUEST=None, **kw):
... return bar, baz is mutabledefault,
egg is None,
REQUEST
>>> inspect.getargspec(foo)[:3]
(['bar', 'baz', 'REQUEST'], None, 'kw')
>>> foo('spam')
('spam', True, None)
(['bar', 'baz', '
egg', '
REQUEST'], None, 'kw')
>>> foo('spam'
, egg=None
)
('spam', True,
True,
None)
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