def apply_rules(*rules):
def decorator(func):
@wraps(func)
def api_rule_check_wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except RQInvalidArgument:
raise
except Exception:
exc_info = sys.exc_info()
t, v, tb = exc_info
try:
call_args = inspect.getcallargs(unwrapper(func), *args, **kwargs)
except TypeError as e:
six.reraise(RQTypeError, RQTypeError(*e.args), tb)
return
try:
for r in rules:
r.verify(func.__name__, call_args[r.arg_name])
except RQInvalidArgument as e:
six.reraise(RQInvalidArgument, e, tb)
return
raise
api_rule_check_wrapper._rq_exception_checked = True
return api_rule_check_wrapper
return decorator
评论列表
文章目录