decorators.py 文件源码

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

项目:aiohttp_auth 作者: gnarlychicken 项目源码 文件源码
def auth_required(func):
    """Utility decorator that checks if a user has been authenticated for this
    request.

    Allows views to be decorated like:

        @auth_required
        def view_func(request):
            pass

    providing a simple means to ensure that whoever is calling the function has
    the correct authentication details.

    Args:
        func: Function object being decorated and raises HTTPForbidden if not

    Returns:
        A function object that will raise web.HTTPForbidden() if the passed
        request does not have the correct permissions to access the view.
    """
    @wraps(func)
    async def wrapper(*args):
        if (await get_auth(args[-1])) is None:
            raise web.HTTPForbidden()

        return await func(*args)

    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号