Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warnings #68

Merged
merged 7 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
27 changes: 16 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,7 @@ 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, 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