def raw_result(wrapped):
"""
Decorator for functions whose output should not be JSON-serialized.
"""
def wrapper(*args, **kwargs):
result = wrapped(*args, **kwargs)
return {'raw_result': result}
# These contortions are necessary to retain compatibility with
# argparse's ability to generate CLI options by signature inspection.
import functools
wrapped_signature = inspect.getargspec(wrapped)
formatted_args = inspect.formatargspec(*wrapped_signature)
compat_name = "_%s" % wrapped.func_name
compat_def = 'lambda %s: %s%s' % (formatted_args.lstrip('(').rstrip(')'),
compat_name, formatted_args)
compat_fn = eval(compat_def, {compat_name: wrapper})
return functools.wraps(wrapped)(compat_fn)
评论列表
文章目录