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

Side by Side Diff: sitescripts/cms/bin/test_server.py

Issue 4817131468226560: Added site_url template variable in order to help generating pages that require a full absolute URL (Closed)
Patch Set: Created Feb. 4, 2014, 11:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sitescripts/cms/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 path = path.rstrip("/") 43 path = path.rstrip("/")
44 if path == "": 44 if path == "":
45 path = source.read_config().get("general", "defaultlocale") 45 path = source.read_config().get("general", "defaultlocale")
46 if "/" not in path: 46 if "/" not in path:
47 path = "%s/%s" % (path, source.read_config().get("general", "defaultpage")) 47 path = "%s/%s" % (path, source.read_config().get("general", "defaultpage"))
48 48
49 locale, page = path.split("/", 1) 49 locale, page = path.split("/", 1)
50 for format in converters.iterkeys(): 50 for format in converters.iterkeys():
51 if source.has_page(page, format): 51 if source.has_page(page, format):
52 return process_page(source, locale, page, format).encode("utf-8") 52 return process_page(source, locale, page, format, "http://127.0.0.1:5000") .encode("utf-8")
53 if source.has_localizable_file(locale, page): 53 if source.has_localizable_file(locale, page):
54 return source.read_localizable_file(locale, page) 54 return source.read_localizable_file(locale, page)
55 55
56 return None 56 return None
57 57
58 @app.route("/", methods = ["GET"]) 58 @app.route("/", methods = ["GET"])
59 @app.route("/<path:path>", methods = ["GET"]) 59 @app.route("/<path:path>", methods = ["GET"])
60 def show(path=""): 60 def show(path=""):
61 data = get_data(path) 61 data = get_data(path)
62 if data == None: 62 if data == None:
63 flask.abort(404) 63 flask.abort(404)
64 64
65 root, ext = os.path.splitext(path) 65 root, ext = os.path.splitext(path)
66 mime = mime_types.get(ext.lower(), "application/octet-stream") 66 mime = mime_types.get(ext.lower(), "application/octet-stream")
67 return data, 200, {"Content-Type": mime} 67 return data, 200, {"Content-Type": mime}
68 68
69 if __name__ == "__main__": 69 if __name__ == "__main__":
70 setupStderr() 70 setupStderr()
71 if len(sys.argv) < 2: 71 if len(sys.argv) < 2:
72 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] 72 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0]
73 sys.exit(1) 73 sys.exit(1)
74 74
75 source = FileSource(sys.argv[1]) 75 source = FileSource(sys.argv[1])
76 76
77 # Make sure to "fix" argv to ensure that restart can succeed 77 # Make sure to "fix" argv to ensure that restart can succeed
78 sys.argv[0:1] = ["-m", "sitescripts.cms.bin.test_server"] 78 sys.argv[0:1] = ["-m", "sitescripts.cms.bin.test_server"]
79 79
80 app.run(debug=True) 80 app.run(debug=True)
OLDNEW
« no previous file with comments | « no previous file | sitescripts/cms/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld