Left: | ||
Right: |
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 if isinstance(data, unicode): | 112 if isinstance(data, unicode): |
113 data = data.encode(UNICODE_ENCODING) | 113 data = data.encode(UNICODE_ENCODING) |
114 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) | 114 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) |
115 | 115 |
116 start_response("200 OK", [("Content-Type", mime)]) | 116 start_response("200 OK", [("Content-Type", mime)]) |
117 return [data] | 117 return [data] |
118 | 118 |
119 if __name__ == "__main__": | 119 if __name__ == "__main__": |
120 | 120 |
121 parser = argparse.ArgumentParser(description='CMS testing server.') | 121 parser = argparse.ArgumentParser(description='CMS testing server.') |
122 parser.add_argument('-b', '--basepath', type=str, help='Base directory (EG: /p ath/to/web.eyeo.com)') | 122 parser.add_argument('basepath', nargs='?', default=os.curdir) |
Sebastian Noack
2016/01/20 17:46:25
Nit: I would simply call it "path".
juliandoucette
2016/01/21 13:46:24
Done.
| |
123 parser.add_argument('-n', '--hostname', type=str, help='Server hostname (EG: l ocalhost, eyeo.com, 0.0.0.0)') | 123 parser.add_argument('-n', '--hostname', default='localhost', type=str, help='S erver hostname (EG: localhost, example.com, 0.0.0.0)') |
Sebastian Noack
2016/01/20 17:46:25
Nit: "Address of the interface the server will lis
Sebastian Noack
2016/01/20 17:46:25
type=str is the default. How about omitting it, if
Sebastian Noack
2016/01/20 18:00:55
--address would be a better name for the option, a
juliandoucette
2016/01/21 13:46:24
Done.
juliandoucette
2016/01/21 13:46:24
Acknowledged.
juliandoucette
2016/01/21 13:46:24
Done.
| |
124 parser.add_argument('-p', '--port', type=str, help='Port number (EG: 8080, 500 0)') | 124 parser.add_argument('-p', '--port', default='5000', type=str, help='Port numbe r (EG: 8080, 5000)') |
Sebastian Noack
2016/01/20 17:46:25
How about type=int? Then you don't need to convert
juliandoucette
2016/01/21 13:46:23
Done.
| |
125 args = parser.parse_args() | 125 args = parser.parse_args() |
126 | 126 |
127 # for backwards compatibility | 127 source = FileSource(args.basepath) |
128 if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]): | 128 hostname = args.hostname |
129 source = FileSource(sys.argv[1]) | 129 port = int(args.port) |
130 hostname = 'localhost' | |
131 port = 5000 | |
132 else: | |
133 source = FileSource(args.basepath or os.curdir) | |
134 hostname = args.hostname or 'localhost' | |
135 port = int(args.port or '5000') | |
136 | 130 |
137 try: | 131 try: |
138 from werkzeug.serving import ThreadedWSGIServer, run_simple | 132 from werkzeug.serving import ThreadedWSGIServer, run_simple |
139 | 133 |
140 # see https://github.com/mitsuhiko/werkzeug/pull/770 | 134 # see https://github.com/mitsuhiko/werkzeug/pull/770 |
141 ThreadedWSGIServer.daemon_threads = True | 135 ThreadedWSGIServer.daemon_threads = True |
142 | 136 |
143 def run(*args, **kwargs): | 137 def run(*args, **kwargs): |
144 # The werkzeug logger must be configured before the | 138 # The werkzeug logger must be configured before the |
145 # root logger. Also we must prevent it from propagating | 139 # root logger. Also we must prevent it from propagating |
(...skipping 18 matching lines...) Expand all Loading... | |
164 return app(environ, start_response) | 158 return app(environ, start_response) |
165 except Exception, e: | 159 except Exception, e: |
166 return show_error(start_response, "500 Internal Server Error", | 160 return show_error(start_response, "500 Internal Server Error", |
167 uri=environ.get("PATH_INFO"), error=e) | 161 uri=environ.get("PATH_INFO"), error=e) |
168 | 162 |
169 server = make_server(host, port, wrapper, ThreadedWSGIServer) | 163 server = make_server(host, port, wrapper, ThreadedWSGIServer) |
170 print " * Running on http://%s:%i/" % server.server_address | 164 print " * Running on http://%s:%i/" % server.server_address |
171 server.serve_forever() | 165 server.serve_forever() |
172 | 166 |
173 run(hostname, port, handler, use_reloader=True, use_debugger=True) | 167 run(hostname, port, handler, use_reloader=True, use_debugger=True) |
OLD | NEW |