arg_checker.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号