Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 # This file is part of Adblock Plus <https://adblockplus.org/>, | 4 # This file is part of Adblock Plus <https://adblockplus.org/>, |
5 # Copyright (C) 2006-2015 Eyeo GmbH | 5 # Copyright (C) 2006-2015 Eyeo GmbH |
6 # | 6 # |
7 # Adblock Plus is free software: you can redistribute it and/or modify | 7 # Adblock Plus is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU General Public License version 3 as | 8 # it under the terms of the GNU General Public License version 3 as |
9 # published by the Free Software Foundation. | 9 # published by the Free Software Foundation. |
10 # | 10 # |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 data = doRewrite([os.path.abspath(path)], []).decode("utf-8") | 48 data = doRewrite([os.path.abspath(path)], []).decode("utf-8") |
49 else: | 49 else: |
50 with io.open(path, "r", encoding="utf-8") as handle: | 50 with io.open(path, "r", encoding="utf-8") as handle: |
51 data = handle.read() | 51 data = handle.read() |
52 data += "\n//# sourceURL=%s" % sourceURL | 52 data += "\n//# sourceURL=%s" % sourceURL |
53 return js_encode(data) | 53 return js_encode(data) |
54 | 54 |
55 @app.route("/<path:path>", methods = ["GET"]) | 55 @app.route("/<path:path>", methods = ["GET"]) |
56 @app.route("/", methods = ["GET"]) | 56 @app.route("/", methods = ["GET"]) |
57 def multiplex(path=""): | 57 def multiplex(path=""): |
58 request_url = urlparse.urlparse(flask.request.url) | 58 base_url = flask.request.url |
59 request_url = urlparse.urlparse(base_url) | |
59 request_path = request_url.path | 60 request_path = request_url.path |
60 islib = request_path.startswith("/lib/") | 61 islib = request_path.startswith("/lib/") |
61 backcompat = request_url.query == "backcompat" | 62 backcompat = request_url.query == "backcompat" |
62 | 63 |
63 rootdir = os.path.dirname(__file__) | 64 rootdir = os.path.dirname(__file__) |
64 if request_path == "/lib.js": | 65 if request_path == "/lib.js": |
65 data = "" | 66 def generate_libs(): |
Sebastian Noack
2015/02/05 11:32:21
Instead concatenating the whole string here, you m
Wladimir Palant
2015/02/05 14:51:26
I think we are getting extremely nit-picky now, co
| |
66 for path, relpath in get_scripts(os.path.join(rootdir, "lib")): | 67 for path, relpath in get_scripts(os.path.join(rootdir, "lib")): |
67 url = urlparse.urljoin(flask.request.url, "/lib/" + relpath) | 68 url = urlparse.urljoin(base_url, "/lib/" + relpath) |
68 data += "require.sources[%s] = %s;\n" % ( | 69 yield "require.sources[%s] = %s;\n" % ( |
69 js_encode(posixpath.splitext(relpath)[0]), | 70 js_encode(posixpath.splitext(relpath)[0]), |
70 script_as_string(path, url, backcompat) | 71 script_as_string(path, url, backcompat) |
71 ) | 72 ) |
72 return (data, 200, {"Content-Type": "application/javascript; charset=utf-8"} ) | 73 return flask.Response(generate_libs(), mimetype="application/javascript") |
73 elif request_path == "/tests.js": | 74 elif request_path == "/tests.js": |
74 data = "var tests = [" | 75 def generate_tests(): |
75 for path, relpath in get_scripts(os.path.join(rootdir, "test", "tests")): | 76 yield "var tests = [" |
76 url = urlparse.urljoin(flask.request.url, "/tests/" + relpath) | 77 for path, relpath in get_scripts(os.path.join(rootdir, "test", "tests")): |
77 data += " %s,\n" % script_as_string(path, url, backcompat) | 78 url = urlparse.urljoin(base_url, "/tests/" + relpath) |
78 data += "];" | 79 yield " %s,\n" % script_as_string(path, url, backcompat) |
79 return (data, 200, {"Content-Type": "application/javascript; charset=utf-8"} ) | 80 yield "];" |
81 return flask.Response(generate_tests(), mimetype="application/javascript") | |
80 else: | 82 else: |
81 if request_path.startswith("/lib/"): | 83 if request_path.startswith("/lib/"): |
82 rootdir = os.path.join(rootdir, "lib") | 84 rootdir = os.path.join(rootdir, "lib") |
83 else: | 85 else: |
84 rootdir = os.path.join(rootdir, "test") | 86 rootdir = os.path.join(rootdir, "test") |
85 if request_path.endswith("/"): | 87 if request_path.endswith("/"): |
86 request_path += "index.html" | 88 request_path += "index.html" |
87 return flask.send_from_directory(rootdir, request_path.lstrip("/")) | 89 return flask.send_from_directory(rootdir, request_path.lstrip("/")) |
88 | 90 |
89 if __name__ == "__main__": | 91 if __name__ == "__main__": |
90 app.run(debug=True) | 92 app.run(debug=True) |
LEFT | RIGHT |