diff options
Diffstat (limited to 'pecan/util.py')
-rw-r--r-- | pecan/util.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pecan/util.py b/pecan/util.py index aa2e683..168ff66 100644 --- a/pecan/util.py +++ b/pecan/util.py @@ -1,10 +1,38 @@ +import inspect import sys +import six + def iscontroller(obj): return getattr(obj, 'exposed', False) +def getargspec(method): + """ + Drill through layers of decorators attempting to locate the actual argspec + for a method. + """ + + argspec = inspect.getargspec(method) + args = argspec[0] + if args and args[0] == 'self': + return argspec + if hasattr(method, '__func__'): + method = method.__func__ + + func_closure = six.get_function_closure(method) + + closure = next( + ( + c for c in func_closure if six.callable(c.cell_contents) + ), + None + ) + method = closure.cell_contents + return getargspec(method) + + def _cfg(f): if not hasattr(f, '_pecan'): f._pecan = {} |