summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-11-14 18:45:53 -0600
committerMichael Merickel <michael@merickel.org>2018-11-14 18:59:43 -0600
commit9ead1d8e84edcb86ea9e07b4d2c31e7b74a098ed (patch)
tree08c0f0389e2e467f8b104a98cc3e6bd19ffc8ab1 /src
parent656ce2b499bd05ceb9b0ae492a0be15a07dc283f (diff)
downloadpyramid-9ead1d8e84edcb86ea9e07b4d2c31e7b74a098ed.tar.gz
pyramid-9ead1d8e84edcb86ea9e07b4d2c31e7b74a098ed.tar.bz2
pyramid-9ead1d8e84edcb86ea9e07b4d2c31e7b74a098ed.zip
move is_unbound_method to pyramid.util
Diffstat (limited to 'src')
-rw-r--r--src/pyramid/compat.py28
-rw-r--r--src/pyramid/util.py34
-rw-r--r--src/pyramid/viewderivers.py9
3 files changed, 30 insertions, 41 deletions
diff --git a/src/pyramid/compat.py b/src/pyramid/compat.py
index 3ad8720d6..12b4b7b00 100644
--- a/src/pyramid/compat.py
+++ b/src/pyramid/compat.py
@@ -76,9 +76,6 @@ def is_nonstr_iter(v):
return hasattr(v, '__iter__')
-im_func = '__func__'
-im_self = '__self__'
-
from http.cookies import SimpleCookie
from html import escape
@@ -95,28 +92,3 @@ from urllib.parse import unquote_to_bytes
def unquote_bytes_to_wsgi(bytestring):
return unquote_to_bytes(bytestring).decode('latin-1')
-
-
-def is_bound_method(ob):
- return inspect.ismethod(ob) and getattr(ob, im_self, None) is not None
-
-
-# support annotations and keyword-only arguments in PY3
-from inspect import getfullargspec as getargspec
-
-
-def is_unbound_method(fn):
- """
- This consistently verifies that the callable is bound to a
- class.
- """
- is_bound = is_bound_method(fn)
-
- if not is_bound and inspect.isroutine(fn):
- spec = getargspec(fn)
- has_self = len(spec.args) > 0 and spec.args[0] == 'self'
-
- if inspect.isfunction(fn) and has_self:
- return True
-
- return False
diff --git a/src/pyramid/util.py b/src/pyramid/util.py
index d3e5d1578..23cce195a 100644
--- a/src/pyramid/util.py
+++ b/src/pyramid/util.py
@@ -6,14 +6,7 @@ import weakref
from pyramid.exceptions import ConfigurationError, CyclicDependencyError
-from pyramid.compat import (
- getargspec,
- im_func,
- is_nonstr_iter,
- bytes_,
- text_,
- native_,
-)
+from pyramid.compat import is_nonstr_iter, bytes_, text_, native_
from pyramid.path import DottedNameResolver as _DottedNameResolver
@@ -616,13 +609,13 @@ def takes_one_arg(callee, attr=None, argname=None):
return False
try:
- argspec = getargspec(fn)
+ argspec = inspect.getfullargspec(fn)
except TypeError:
return False
args = argspec[0]
- if hasattr(fn, im_func) or ismethod:
+ if hasattr(fn, '__func__') or ismethod:
# it's an instance method (or unbound method on py2)
if not args:
return False
@@ -653,3 +646,24 @@ class SimpleSerializer(object):
def dumps(self, appstruct):
return bytes_(appstruct)
+
+
+def is_bound_method(ob):
+ return inspect.ismethod(ob) and getattr(ob, '__self__', None) is not None
+
+
+def is_unbound_method(fn):
+ """
+ This consistently verifies that the callable is bound to a
+ class.
+ """
+ is_bound = is_bound_method(fn)
+
+ if not is_bound and inspect.isroutine(fn):
+ spec = inspect.getfullargspec(fn)
+ has_self = len(spec.args) > 0 and spec.args[0] == 'self'
+
+ if inspect.isfunction(fn) and has_self:
+ return True
+
+ return False
diff --git a/src/pyramid/viewderivers.py b/src/pyramid/viewderivers.py
index fbe0c252c..181cc9e5c 100644
--- a/src/pyramid/viewderivers.py
+++ b/src/pyramid/viewderivers.py
@@ -17,11 +17,14 @@ from pyramid.interfaces import (
IViewMapperFactory,
)
-from pyramid.compat import is_bound_method, is_unbound_method
-
from pyramid.exceptions import ConfigurationError
from pyramid.httpexceptions import HTTPForbidden
-from pyramid.util import object_description, takes_one_arg
+from pyramid.util import (
+ object_description,
+ takes_one_arg,
+ is_bound_method,
+ is_unbound_method,
+)
from pyramid.view import render_view_to_response
from pyramid import renderers