tor_cache.py 文件源码

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

项目:freshonions-torscraper 作者: dirtyfilthy 项目源码 文件源码
def __call__(self, f):
        @functools.wraps(f)
        def my_decorator(*args, **kwargs):
            global _is_cached
            _is_cached = True
            if _cache is None:
                return f(*args, **kwargs)
            response = _cache.get(request.full_path)
            if response is None:
                response = f(*args, **kwargs)
                _cache.set(request.path, response, self.timeout)
            _is_cached = False

            if self.render_layout:
                wrapped_response = make_response("%s%s%s" % (render_template("layout_header.html"), response, render_template("layout_footer.html")))
                if is_response(response):
                    wrapped_response.status_code = response.status_code
                    wrapped_response.headers     = response.headers
                    wrapped_response.status      = response.status
                    wrapped_response.mimetype    = response.mimetype
                return wrapped_response
            else:
                return response

        functools.update_wrapper(my_decorator, f)
        return my_decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号