auth.py 文件源码

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

项目:stethoscope 作者: Netflix 项目源码 文件源码
def token_required(self, func=None, callback=None):
    """Decorator for endpoints which require a verified user."""
    # logger.debug("token_required received func={!r}, callback={!r}", func, callback)
    if func is None:
      # called with optional arguments; return value will be called without, so pass them through
      return functools.partial(self.token_required, callback=callback)

    @six.wraps(func)
    def decorator(request, *args, **kwargs):
      userinfo = self.check_token(request)

      kwargs['userinfo'] = userinfo
      args = (request,) + args

      if callback is not None:
        # logger.debug("calling {!r} with args={!r} and kwargs={!r}", callback, args, kwargs)
        callback(*args, **kwargs)

      # logger.debug("calling {!r} with args={!r} and kwargs={!r}", func, args, kwargs)
      return func(*args, **kwargs)

    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号