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

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

Issue 5640548127866880: Issue 2678 - Don't consider local files and Windows registry when guessing mime types (Closed)
Patch Set: Created June 12, 2015, 9: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 | no next file » | 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-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 28 matching lines...) Expand all
39 {% set code = status.split()|first|int %} 39 {% set code = status.split()|first|int %}
40 {% if code == 404 %} 40 {% if code == 404 %}
41 <p>No page found for the address {{uri}}.</p> 41 <p>No page found for the address {{uri}}.</p>
42 {% elif code == 500 %} 42 {% elif code == 500 %}
43 <p>An error occurred while processing the request for {{uri}}:</p> 43 <p>An error occurred while processing the request for {{uri}}:</p>
44 <pre>{{error}}</pre> 44 <pre>{{error}}</pre>
45 {% endif %} 45 {% endif %}
46 </body> 46 </body>
47 </html>""" 47 </html>"""
48 48
49 # Create our own instance, the default one will introduce "random" host-specific 49 # Initilize the mimetypes modules manually for consistent behavior,
50 # behavior by parsing local config files. 50 # ignoring local files and Windows Registry.
51 mime_types = mimetypes.MimeTypes() 51 mimetypes.init([])
Wladimir Palant 2015/06/29 10:42:32 Re-reading the source code I can see the issue - M
52 52
53 def get_page(path): 53 def get_page(path):
54 path = path.strip("/") 54 path = path.strip("/")
55 if path == "": 55 if path == "":
56 path = source.read_config().get("general", "defaultlocale") 56 path = source.read_config().get("general", "defaultlocale")
57 if "/" in path: 57 if "/" in path:
58 locale, page = path.split("/", 1) 58 locale, page = path.split("/", 1)
59 else: 59 else:
60 locale, page = path, "" 60 locale, page = path, ""
61 61
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 for fragment in template.stream(status=status, **kwargs): 98 for fragment in template.stream(status=status, **kwargs):
99 yield fragment.encode(UNICODE_ENCODING) 99 yield fragment.encode(UNICODE_ENCODING)
100 100
101 def handler(environ, start_response): 101 def handler(environ, start_response):
102 path = environ.get("PATH_INFO") 102 path = environ.get("PATH_INFO")
103 103
104 data = get_data(path) 104 data = get_data(path)
105 if data is None: 105 if data is None:
106 return show_error(start_response, "404 Not Found", uri=path) 106 return show_error(start_response, "404 Not Found", uri=path)
107 107
108 mime = mime_types.guess_type(path)[0] or "text/html" 108 mime = mimetypes.guess_type(path)[0] or "text/html"
109 109
110 if isinstance(data, unicode): 110 if isinstance(data, unicode):
111 data = data.encode(UNICODE_ENCODING) 111 data = data.encode(UNICODE_ENCODING)
112 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) 112 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING)
113 113
114 start_response("200 OK", [("Content-Type", mime)]) 114 start_response("200 OK", [("Content-Type", mime)])
115 return [data] 115 return [data]
116 116
117 if __name__ == "__main__": 117 if __name__ == "__main__":
118 if len(sys.argv) < 2: 118 if len(sys.argv) < 2:
(...skipping 24 matching lines...) Expand all
143 return app(environ, start_response) 143 return app(environ, start_response)
144 except Exception, e: 144 except Exception, e:
145 return show_error(start_response, "500 Internal Server Error", 145 return show_error(start_response, "500 Internal Server Error",
146 uri=environ.get("PATH_INFO"), error=e) 146 uri=environ.get("PATH_INFO"), error=e)
147 147
148 server = make_server(host, port, wrapper) 148 server = make_server(host, port, wrapper)
149 print " * Running on http://%s:%i/" % server.server_address 149 print " * Running on http://%s:%i/" % server.server_address
150 server.serve_forever() 150 server.serve_forever()
151 151
152 run("localhost", 5000, handler, use_reloader=True, use_debugger=True) 152 run("localhost", 5000, handler, use_reloader=True, use_debugger=True)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld