OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import atexit | 5 import atexit |
6 import datetime | 6 import datetime |
7 import email.utils | 7 import email.utils |
8 import errno | 8 import errno |
9 import gzip | 9 import gzip |
10 import hashlib | 10 import hashlib |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 assert mappings | 196 assert mappings |
197 handler_class = _get_handler_class_for_path(mappings) | 197 handler_class = _get_handler_class_for_path(mappings) |
198 | 198 |
199 try: | 199 try: |
200 httpd = _SilentTCPServer(('127.0.0.1', host_port), handler_class) | 200 httpd = _SilentTCPServer(('127.0.0.1', host_port), handler_class) |
201 atexit.register(httpd.shutdown) | 201 atexit.register(httpd.shutdown) |
202 | 202 |
203 http_thread = threading.Thread(target=httpd.serve_forever) | 203 http_thread = threading.Thread(target=httpd.serve_forever) |
204 http_thread.daemon = True | 204 http_thread.daemon = True |
205 http_thread.start() | 205 http_thread.start() |
206 print 'Started http://%s:%d to host %s.' % (httpd.server_address[0], | |
207 httpd.server_address[1], | |
208 str(mappings)) | |
209 return httpd.server_address | 206 return httpd.server_address |
210 except socket.error as v: | 207 except socket.error as v: |
211 error_code = v[0] | 208 error_code = v[0] |
212 print 'Failed to start http server for %s on port %d: %s.' % ( | 209 print 'Failed to start http server for %s on port %d: %s.' % ( |
213 str(mappings), host_port, os.strerror(error_code)) | 210 str(mappings), host_port, os.strerror(error_code)) |
214 if error_code == errno.EADDRINUSE: | 211 if error_code == errno.EADDRINUSE: |
215 print (' Run `fuser %d/tcp` to find out which process is using the port.' | 212 print (' Run `fuser %d/tcp` to find out which process is using the port.' |
216 % host_port) | 213 % host_port) |
217 print '---' | 214 print '---' |
218 raise | 215 raise |
OLD | NEW |