Index: sitescripts/web/bin/test_server.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/sitescripts/web/bin/test_server.py |
@@ -0,0 +1,67 @@ |
+# coding: utf-8 |
+ |
+# This file is part of the Adblock Plus web scripts, |
+# Copyright (C) 2006-2013 Eyeo GmbH |
+# |
+# Adblock Plus is free software: you can redistribute it and/or modify |
+# it under the terms of the GNU General Public License version 3 as |
+# published by the Free Software Foundation. |
+# |
+# Adblock Plus is distributed in the hope that it will be useful, |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+# GNU General Public License for more details. |
+# |
+# You should have received a copy of the GNU General Public License |
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ |
+import sys, os, flask |
+from sitescripts.utils import setupStderr |
+from sitescripts.web.utils import process_page |
+from sitescripts.web.sources import FileSource |
+from sitescripts.web.converters import converters |
+ |
+app = flask.Flask("sitescripts.web.bin.test_server") |
+source = None |
+ |
+def get_data(path): |
+ if "/" in path: |
+ locale, page = path.split("/", 1) |
+ for format in converters.iterkeys(): |
+ if source.has_page(page, format): |
+ return process_page(source, locale, page, format) |
+ if source.has_localizable_file(locale, page): |
+ return source.read_localizable_file(locale, page) |
+ |
+ if source.has_static(path): |
+ return source.read_static(path) |
+ |
+ return None |
+ |
+@app.route("/<path:path>", methods = ["GET"]) |
+def show(path): |
+ data = get_data(path) |
+ if data == None: |
+ flask.abort(404) |
+ |
+ root, ext = os.path.splitext(path) |
+ if ext == ".js": |
+ mime = "text/js; charset=utf-8" |
+ elif ext == ".css": |
+ mime = "text/css; charset=utf-8" |
+ elif ext == ".png": |
+ mime = "image/png" |
+ elif ext == "": |
+ mime = "text/html; charset=utf-8" |
+ else: |
+ mime = "application/octet-stream" |
+ return data, 200, {"Content-Type": mime} |
+ |
+if __name__ == "__main__": |
+ setupStderr() |
+ if len(sys.argv) < 2: |
+ print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] |
+ sys.exit(1) |
+ |
+ source = FileSource(sys.argv[1]) |
+ app.run(debug=True, use_reloader=False) |