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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 if __name__ == "__main__": | 100 if __name__ == "__main__": |
101 if len(sys.argv) < 2: | 101 if len(sys.argv) < 2: |
102 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] | 102 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] |
103 sys.exit(1) | 103 sys.exit(1) |
104 | 104 |
105 source = FileSource(sys.argv[1]) | 105 source = FileSource(sys.argv[1]) |
106 | 106 |
107 try: | 107 try: |
108 from werkzeug.serving import run_simple | 108 from werkzeug.serving import run_simple |
| 109 def run(*args, **kwargs): |
| 110 # The werkzeug logger must be configured before the |
| 111 # root logger. Also we must prevent it from propagating |
| 112 # messages, otherwise messages are logged twice. |
| 113 import logging |
| 114 logger = logging.getLogger("werkzeug") |
| 115 logger.propagate = False |
| 116 logger.setLevel(logging.INFO) |
| 117 logger.addHandler(logging.StreamHandler()) |
| 118 |
| 119 run_simple(*args, **kwargs) |
109 except ImportError: | 120 except ImportError: |
110 from wsgiref.simple_server import make_server | 121 from wsgiref.simple_server import make_server |
111 def run_simple(host, port, app, **kwargs): | 122 def run(host, port, app, **kwargs): |
112 def wrapper(environ, start_response): | 123 def wrapper(environ, start_response): |
113 try: | 124 try: |
114 return app(environ, start_response) | 125 return app(environ, start_response) |
115 except Exception, e: | 126 except Exception, e: |
116 return show_error(start_response, "500 Internal Server Error", | 127 return show_error(start_response, "500 Internal Server Error", |
117 uri=environ.get("PATH_INFO"), error=e) | 128 uri=environ.get("PATH_INFO"), error=e) |
118 | 129 |
119 server = make_server(host, port, wrapper) | 130 server = make_server(host, port, wrapper) |
120 print " * Running on http://%s:%i/" % server.server_address | 131 print " * Running on http://%s:%i/" % server.server_address |
121 server.serve_forever() | 132 server.serve_forever() |
122 | 133 |
123 run_simple("localhost", 5000, handler, use_reloader=True, use_debugger=True) | 134 run("localhost", 5000, handler, use_reloader=True, use_debugger=True) |
OLD | NEW |