Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This is a simple HTTP server used for testing Chrome. | 6 """This is a simple HTTP server used for testing Chrome. |
| 7 | 7 |
| 8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
| 9 By default, it listens on an ephemeral port and sends the port number back to | 9 By default, it listens on an ephemeral port and sends the port number back to |
| 10 the originating process over a pipe. The originating process can specify an | 10 the originating process over a pipe. The originating process can specify an |
| 11 explicit port if necessary. | 11 explicit port if necessary. |
| 12 It can use https if you specify the flag --https=CERT where CERT is the path | 12 It can use https if you specify the flag --https=CERT where CERT is the path |
| 13 to a pem file containing the certificate and private key that should be used. | 13 to a pem file containing the certificate and private key that should be used. |
| 14 """ | 14 """ |
| 15 | 15 |
| 16 import base64 | 16 import base64 |
| 17 import BaseHTTPServer | 17 import BaseHTTPServer |
| 18 import cgi | 18 import cgi |
| 19 import optparse | 19 import optparse |
| 20 import os | 20 import os |
| 21 import re | 21 import re |
| 22 import shutil | 22 import shutil |
| 23 import SocketServer | 23 import SocketServer |
| 24 import sys | 24 import sys |
| 25 import struct | 25 import struct |
| 26 import time | 26 import time |
| 27 import urlparse | 27 import urlparse |
| 28 import warnings | 28 import warnings |
| 29 | 29 |
| 30 if sys.version_info < (2, 6): | |
|
Paweł Hajdan Jr.
2010/11/18 10:35:12
Hmmm. Can we use the same version of the library,
akalin
2010/11/18 22:38:34
I get warnings if I try to use simplejson only. I
| |
| 31 import simplejson as json | |
| 32 else: | |
| 33 import json | |
| 34 | |
| 30 # Ignore deprecation warnings, they make our output more cluttered. | 35 # Ignore deprecation warnings, they make our output more cluttered. |
| 31 warnings.filterwarnings("ignore", category=DeprecationWarning) | 36 warnings.filterwarnings("ignore", category=DeprecationWarning) |
| 32 | 37 |
| 33 import pyftpdlib.ftpserver | 38 import pyftpdlib.ftpserver |
| 34 import tlslite | 39 import tlslite |
| 35 import tlslite.api | 40 import tlslite.api |
| 36 | 41 |
| 37 try: | 42 try: |
| 38 import hashlib | 43 import hashlib |
| 39 _new_md5 = hashlib.md5 | 44 _new_md5 = hashlib.md5 |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 | 1300 |
| 1296 # Instantiate FTP server class and listen to 127.0.0.1:port | 1301 # Instantiate FTP server class and listen to 127.0.0.1:port |
| 1297 address = ('127.0.0.1', port) | 1302 address = ('127.0.0.1', port) |
| 1298 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) | 1303 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) |
| 1299 listen_port = server.socket.getsockname()[1] | 1304 listen_port = server.socket.getsockname()[1] |
| 1300 print 'FTP server started on port %d...' % listen_port | 1305 print 'FTP server started on port %d...' % listen_port |
| 1301 | 1306 |
| 1302 # Notify the parent that we've started. (BaseServer subclasses | 1307 # Notify the parent that we've started. (BaseServer subclasses |
| 1303 # bind their sockets on construction.) | 1308 # bind their sockets on construction.) |
| 1304 if options.startup_pipe is not None: | 1309 if options.startup_pipe is not None: |
| 1310 server_data = { | |
| 1311 'port': listen_port | |
| 1312 } | |
| 1313 server_data_json = json.dumps(server_data) | |
| 1314 print 'sending server_data: %s' % server_data_json | |
|
Paweł Hajdan Jr.
2010/11/18 10:35:12
nit: Only for debugging?
| |
| 1315 server_data_len = len(server_data_json) | |
| 1305 if sys.platform == 'win32': | 1316 if sys.platform == 'win32': |
| 1306 fd = msvcrt.open_osfhandle(options.startup_pipe, 0) | 1317 fd = msvcrt.open_osfhandle(options.startup_pipe, 0) |
| 1307 else: | 1318 else: |
| 1308 fd = options.startup_pipe | 1319 fd = options.startup_pipe |
| 1309 startup_pipe = os.fdopen(fd, "w") | 1320 startup_pipe = os.fdopen(fd, "w") |
| 1310 # Write the listening port as a 2 byte value. This is _not_ using | 1321 # First write the data length as an unsigned 4-byte value. This |
| 1311 # network byte ordering since the other end of the pipe is on the same | 1322 # is _not_ using network byte ordering since the other end of the |
| 1312 # machine. | 1323 # pipe is on the same machine. |
| 1313 startup_pipe.write(struct.pack('@H', listen_port)) | 1324 startup_pipe.write(struct.pack('=L', server_data_len)) |
| 1325 startup_pipe.write(server_data_json) | |
| 1314 startup_pipe.close() | 1326 startup_pipe.close() |
| 1315 | 1327 |
| 1316 try: | 1328 try: |
| 1317 server.serve_forever() | 1329 server.serve_forever() |
| 1318 except KeyboardInterrupt: | 1330 except KeyboardInterrupt: |
| 1319 print 'shutting down server' | 1331 print 'shutting down server' |
| 1320 server.stop = True | 1332 server.stop = True |
| 1321 | 1333 |
| 1322 if __name__ == '__main__': | 1334 if __name__ == '__main__': |
| 1323 option_parser = optparse.OptionParser() | 1335 option_parser = optparse.OptionParser() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 'option may appear multiple times, indicating ' | 1367 'option may appear multiple times, indicating ' |
| 1356 'multiple algorithms should be enabled.'); | 1368 'multiple algorithms should be enabled.'); |
| 1357 option_parser.add_option('', '--file-root-url', default='/files/', | 1369 option_parser.add_option('', '--file-root-url', default='/files/', |
| 1358 help='Specify a root URL for files served.') | 1370 help='Specify a root URL for files served.') |
| 1359 option_parser.add_option('', '--startup-pipe', type='int', | 1371 option_parser.add_option('', '--startup-pipe', type='int', |
| 1360 dest='startup_pipe', | 1372 dest='startup_pipe', |
| 1361 help='File handle of pipe to parent process') | 1373 help='File handle of pipe to parent process') |
| 1362 options, args = option_parser.parse_args() | 1374 options, args = option_parser.parse_args() |
| 1363 | 1375 |
| 1364 sys.exit(main(options, args)) | 1376 sys.exit(main(options, args)) |
| OLD | NEW |