__init__.py 文件源码

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

项目:flask-alcohol 作者: natfoster82 项目源码 文件源码
def make_proxy_method(cls, name):
        """
        Creates a proxy function that can be used by Flasks routing. The
        proxy instantiates the FlaskView subclass and calls the appropriate
        method.

        :param name: the name of the method to create a proxy for
        """

        i = cls()
        view = getattr(i, name)

        if cls.__decorators__:
            for decorator in cls.__decorators__:
                view = decorator(view)

        @functools.wraps(view)
        def proxy(**forgettable_view_args):
            # Always use the global request object's view_args, because they
            # can be modified by intervening function before an endpoint or
            # wrapper gets called. This matches Flask's behavior.
            del forgettable_view_args

            response = view(**request.view_args)
            if not isinstance(response, Response):
                response = make_response(response)

            return response

        return proxy
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号