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

Delta Between Two Patch Sets: cms/bin/test_server.py

Issue 29328527: Issue 3112 - Support use of sitescripts URL handlers from the test server (Closed)
Left Patch Set: Created Sept. 23, 2015, 1:24 p.m.
Right Patch Set: Avoid overzealous exception catching Created Sept. 23, 2015, 1:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 mime = "text/html; encoding=%s" % UNICODE_ENCODING 96 mime = "text/html; encoding=%s" % UNICODE_ENCODING
97 start_response(status, [("Content-Type", mime)]) 97 start_response(status, [("Content-Type", mime)])
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 # First check for a relevant URL handler in sitescripts 104 # First check for a relevant URL handler in sitescripts
105 try: 105 try:
106 from sitescripts.web import get_handler 106 from sitescripts.web import get_handler
Sebastian Noack 2015/09/29 11:45:30 I'm not too happy with this change. I don't think
107 return get_handler(path)(environ, start_response) 107 dynamic_handler = get_handler(path)
108 except (KeyError, ImportError): 108 except (KeyError, ImportError):
109 pass 109 pass
110 else:
111 return dynamic_handler(environ, start_response)
110 112
111 # Otherwise serve a static file / page 113 # Otherwise serve a static file / page
112 data = get_data(path) 114 data = get_data(path)
113 if data is None: 115 if data is None:
114 return show_error(start_response, "404 Not Found", uri=path) 116 return show_error(start_response, "404 Not Found", uri=path)
115 117
116 mime = mimetypes.guess_type(path)[0] or "text/html" 118 mime = mimetypes.guess_type(path)[0] or "text/html"
117 119
118 if isinstance(data, unicode): 120 if isinstance(data, unicode):
119 data = data.encode(UNICODE_ENCODING) 121 data = data.encode(UNICODE_ENCODING)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return app(environ, start_response) 162 return app(environ, start_response)
161 except Exception, e: 163 except Exception, e:
162 return show_error(start_response, "500 Internal Server Error", 164 return show_error(start_response, "500 Internal Server Error",
163 uri=environ.get("PATH_INFO"), error=e) 165 uri=environ.get("PATH_INFO"), error=e)
164 166
165 server = make_server(host, port, wrapper, ThreadedWSGIServer) 167 server = make_server(host, port, wrapper, ThreadedWSGIServer)
166 print " * Running on http://%s:%i/" % server.server_address 168 print " * Running on http://%s:%i/" % server.server_address
167 server.serve_forever() 169 server.serve_forever()
168 170
169 run("localhost", 5000, handler, use_reloader=True, use_debugger=True) 171 run("localhost", 5000, handler, use_reloader=True, use_debugger=True)
LEFTRIGHT
« README.md ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld