Skip to content

Commit

Permalink
fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr committed Oct 5, 2018
1 parent 6cba6d8 commit 68263d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/AccessControl/requestmethod.py
Expand Up @@ -11,31 +11,34 @@
#
##############################################################################

import inspect

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

try:
from inspect import getfullargspec
except ImportError: # Python 2
from inspect import getargspec as getfullargspec

from inspect 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 +84,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
2 changes: 1 addition & 1 deletion src/AccessControl/safe_formatter.py
@@ -1,5 +1,5 @@
from AccessControl.ZopeGuards import guarded_getattr, guarded_getitem
from collections import Mapping
from collections.abc import Mapping

import string
import six
Expand Down

0 comments on commit 68263d3

Please sign in to comment.