| OLD | NEW | 
|---|
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 94   env = jinja2.Environment(autoescape=True) | 94   env = jinja2.Environment(autoescape=True) | 
| 95   template = env.from_string(ERROR_TEMPLATE) | 95   template = env.from_string(ERROR_TEMPLATE) | 
| 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 | 
|  | 105   try: | 
|  | 106     from sitescripts.web import get_handler | 
|  | 107     return get_handler(path)(environ, start_response) | 
|  | 108   except (KeyError, ImportError): | 
|  | 109     pass | 
|  | 110 | 
|  | 111   # Otherwise serve a static file / page | 
| 104   data = get_data(path) | 112   data = get_data(path) | 
| 105   if data is None: | 113   if data is None: | 
| 106     return show_error(start_response, "404 Not Found", uri=path) | 114     return show_error(start_response, "404 Not Found", uri=path) | 
| 107 | 115 | 
| 108   mime = mimetypes.guess_type(path)[0] or "text/html" | 116   mime = mimetypes.guess_type(path)[0] or "text/html" | 
| 109 | 117 | 
| 110   if isinstance(data, unicode): | 118   if isinstance(data, unicode): | 
| 111     data = data.encode(UNICODE_ENCODING) | 119     data = data.encode(UNICODE_ENCODING) | 
| 112     mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) | 120     mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) | 
| 113 | 121 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 152           return app(environ, start_response) | 160           return app(environ, start_response) | 
| 153         except Exception, e: | 161         except Exception, e: | 
| 154           return show_error(start_response, "500 Internal Server Error", | 162           return show_error(start_response, "500 Internal Server Error", | 
| 155               uri=environ.get("PATH_INFO"), error=e) | 163               uri=environ.get("PATH_INFO"), error=e) | 
| 156 | 164 | 
| 157       server = make_server(host, port, wrapper, ThreadedWSGIServer) | 165       server = make_server(host, port, wrapper, ThreadedWSGIServer) | 
| 158       print " * Running on http://%s:%i/" % server.server_address | 166       print " * Running on http://%s:%i/" % server.server_address | 
| 159       server.serve_forever() | 167       server.serve_forever() | 
| 160 | 168 | 
| 161   run("localhost", 5000, handler, use_reloader=True, use_debugger=True) | 169   run("localhost", 5000, handler, use_reloader=True, use_debugger=True) | 
| OLD | NEW | 
|---|