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

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

Issue 5217703262420992: Issue 2181 - [cms] Test server should accept default page for subdirectories as well (Closed)
Patch Set: Ask for forgiveness Created March 20, 2015, 3:41 p.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 | cms/sources.py » ('j') | cms/sources.py » ('J')
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-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 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 24 matching lines...) Expand all
35 ".jpeg": "image/jpeg", 35 ".jpeg": "image/jpeg",
36 } 36 }
37 37
38 def get_data(path): 38 def get_data(path):
39 if source.has_static(path): 39 if source.has_static(path):
40 return source.read_static(path) 40 return source.read_static(path)
41 41
42 path = path.rstrip("/") 42 path = path.rstrip("/")
43 if path == "": 43 if path == "":
44 path = source.read_config().get("general", "defaultlocale") 44 path = source.read_config().get("general", "defaultlocale")
45 if "/" not in path: 45 if "/" in path:
46 path = "%s/%s" % (path, source.read_config().get("general", "defaultpage")) 46 locale, page = path.split("/", 1)
47 else:
48 locale, page = path, ""
47 49
48 locale, page = path.split("/", 1) 50 default_page = source.read_config().get("general", "defaultpage")
51 alternative_page = "/".join([page, default_page]).lstrip("/")
49 for format in converters.iterkeys(): 52 for format in converters.iterkeys():
50 if source.has_page(page, format): 53 for p in (page, alternative_page):
51 return process_page(source, locale, page, format, "http://127.0.0.1:5000") .encode("utf-8") 54 if source.has_page(p, format):
55 return process_page(source, locale, p, format, "http://127.0.0.1:5000"). encode("utf-8")
52 if source.has_localizable_file(locale, page): 56 if source.has_localizable_file(locale, page):
53 return source.read_localizable_file(locale, page) 57 return source.read_localizable_file(locale, page)
54 58
55 return None 59 return None
56 60
57 @app.route("/", methods = ["GET"]) 61 @app.route("/", methods = ["GET"])
58 @app.route("/<path:path>", methods = ["GET"]) 62 @app.route("/<path:path>", methods = ["GET"])
59 def show(path=""): 63 def show(path=""):
60 data = get_data(path) 64 data = get_data(path)
61 if data == None: 65 if data == None:
62 flask.abort(404) 66 flask.abort(404)
63 67
64 root, ext = os.path.splitext(path) 68 root, ext = os.path.splitext(path)
65 mime = mime_types.get(ext.lower(), "application/octet-stream") 69 mime = mime_types.get(ext.lower(), "application/octet-stream")
66 return data, 200, {"Content-Type": mime} 70 return data, 200, {"Content-Type": mime}
67 71
68 if __name__ == "__main__": 72 if __name__ == "__main__":
69 if len(sys.argv) < 2: 73 if len(sys.argv) < 2:
70 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] 74 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0]
71 sys.exit(1) 75 sys.exit(1)
72 76
73 source = FileSource(sys.argv[1]) 77 source = FileSource(sys.argv[1])
74 78
75 app.run(debug=True) 79 app.run(debug=True)
OLDNEW
« no previous file with comments | « no previous file | cms/sources.py » ('j') | cms/sources.py » ('J')

Powered by Google App Engine
This is Rietveld