Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/web/bin/test_server.py

Issue 17817001: Simple CMS as Anwiki replacement (Closed)
Patch Set: Various improvements Created Oct. 24, 2013, 11:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/web/bin/generate_static_pages.py ('k') | sitescripts/web/converters.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/web/bin/test_server.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/web/bin/test_server.py
@@ -0,0 +1,71 @@
+# 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 ...utils import setupStderr
+from ..utils import process_page
+from ..sources import FileSource
+from ..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).encode("utf-8")
+ 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])
+
+ # Make sure to "fix" argv to ensure that restart can succeed
+ sys.argv[0:1] = ["-m", "sitescripts.web.bin.test_server"]
+
+ app.run(debug=True)
« no previous file with comments | « sitescripts/web/bin/generate_static_pages.py ('k') | sitescripts/web/converters.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld