callbacks.py 文件源码

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

项目:GridLight-Server 作者: Lunabit 项目源码 文件源码
def before_request():
    g.res = LunabitResponse()

    # all routes must have a trailing slash, will append if doesn't exist
    if not request.path.endswith('/'):
        request.path = ''.join([request.path, '/'])
    # removing api version from beginning of string for proper routing
    request_path = str(request.url_rule) if request.url_rule else request.path

    url_rules = [r.rule for r in app.url_map.iter_rules()]
    if request_path in url_rules:
        for r in app.url_map.iter_rules():
            if r.rule == request_path and request.method in r.methods:
                print(r.methods)
                try:
                    g.req = LunabitRequest.from_data(request.method, request)
                    g.user = g.req.user
                    break
                except GridlightException as e:
                    raise InvalidUsage(message=str(e))
        else:
            err = ''.join(["URL '", request_path, "' does not allow the method '", request.method,"'."])
            print_log(err)
            raise InvalidUsage(message=err, status_code=405)
    else:
        err = ''.join(["URL '", request_path, "' does not exist."])
        print_log(err)
        raise InvalidUsage(message=err, status_code=404)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号