def get(self, url, md5hash): url = urllib.unquote(url) if utils.md5hash(url) != md5hash: self.response.status_int = 403 return try: r = requests.get(url, timeout=50) except requests.RequestException: self.response.status_int = 502 self.response.write("Timeout") else: self.response.headers.update(r.headers) self.response.write(r.content)
def jinja2(self): default_config = jinja2.default_config environment_args = default_config["environment_args"] environment_args["auto_reload"] = False environment_args["extensions"].append("jinja2.ext.loopcontrols") default_config["globals"] = { "app": self.app, "uri_for": webapp2.uri_for, } default_config["filters"] = { "mid2url": utils.mid2url, "rfc822": utils.rfc822, "strftime": utils.strftime, "expandurl": utils.expandurl, "expandname": utils.expandname, "quote": urllib.quote, "utf8": lambda x: x.encode("utf8"), "imgproxy": lambda url: urlparse.urljoin("https://" + webapp2.get_request().host, webapp2.uri_for("proxy", url=urllib.quote(url, ""), md5hash=utils.md5hash(url))), "original_pic": utils.original_pic, } default_config["template_path"] = path.normpath(path.join(path.dirname(__file__), "../templates")) return jinja2.get_jinja2(app=self.app)