Skip to content

Commit

Permalink
Merge d79e348 into f86951a
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr committed Oct 5, 2018
2 parents f86951a + d79e348 commit 9083653
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
'zope.schema',
'zope.security',
'zope.testing',
'funcsigs;python_version<"3.3"',
],
include_package_data=True,
zip_safe=False,
Expand Down
28 changes: 17 additions & 11 deletions src/AccessControl/requestmethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,36 @@
#
##############################################################################

import inspect

import six
from zExceptions import Forbidden
from zope.publisher.interfaces.browser import IBrowserRequest

try:
if six.PY3:
from inspect import getfullargspec
except ImportError: # Python 2
from inspect import signature
else: # Python 2
from inspect import getargspec as getfullargspec

from funcsigs import signature

_default = []


def _buildFacade(name, spec, docstring):
def _buildFacade(name, method, docstring):
"""Build a facade function, matching the decorated method in signature.
Note that defaults are replaced by _default, and _curried will reconstruct
these to preserve mutable defaults.
"""
args = inspect.formatargspec(formatvalue=lambda v: '=_default', *spec)
callargs = inspect.formatargspec(formatvalue=lambda v: '', *spec)
return 'def %s%s:\n """%s"""\n return _curried%s' % (
name, args, docstring, callargs)
sig = signature(method)
args = []
for v in sig.parameters.values():
argstr = str(v)
args.append(
argstr if '=' not in argstr else '{}=_default'.format(v.name))
callargs = ', '.join(sig.parameters.keys())
return 'def %s(%s):\n """%s"""\n return _curried(%s)' % (
name, ', '.join(args), docstring, callargs)


def requestmethod(*methods):
Expand Down Expand Up @@ -81,7 +86,8 @@ def _curried(*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(name, spec, callable.__doc__), facade_globs)
# exec(_buildFacade(name, spec, callable.__doc__), facade_globs)
exec(_buildFacade(name, callable, callable.__doc__), facade_globs)
return facade_globs[name]

return _methodtest
Expand Down
6 changes: 5 additions & 1 deletion src/AccessControl/safe_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from AccessControl.ZopeGuards import guarded_getattr, guarded_getitem
from collections import Mapping

import string
import six
Expand All @@ -10,6 +9,11 @@
except ImportError:
pass

if six.PY3:
from collections.abc import Mapping
else:
from collections import Mapping


def formatter_field_name_split(field_name):
if six.PY3:
Expand Down

0 comments on commit 9083653

Please sign in to comment.