Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 3368012: Wait on a pipe for the test server to start up (Closed)
Patch Set: Sigh. Rebase onto trunk. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/test/test_server_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 It defaults to living on localhost:8888. 9 It defaults to living on localhost:8888.
10 It can use https if you specify the flag --https=CERT where CERT is the path 10 It can use https if you specify the flag --https=CERT where CERT is the path
(...skipping 21 matching lines...) Expand all
32 import tlslite 32 import tlslite
33 import tlslite.api 33 import tlslite.api
34 34
35 try: 35 try:
36 import hashlib 36 import hashlib
37 _new_md5 = hashlib.md5 37 _new_md5 = hashlib.md5
38 except ImportError: 38 except ImportError:
39 import md5 39 import md5
40 _new_md5 = md5.new 40 _new_md5 = md5.new
41 41
42 if sys.platform == 'win32':
43 import msvcrt
44
42 SERVER_HTTP = 0 45 SERVER_HTTP = 0
43 SERVER_FTP = 1 46 SERVER_FTP = 1
44 47
45 debug_output = sys.stderr 48 debug_output = sys.stderr
46 def debug(str): 49 def debug(str):
47 debug_output.write(str + "\n") 50 debug_output.write(str + "\n")
48 debug_output.flush() 51 debug_output.flush()
49 52
50 class StoppableHTTPServer(BaseHTTPServer.HTTPServer): 53 class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
51 """This is a specialization of of BaseHTTPServer to allow it 54 """This is a specialization of of BaseHTTPServer to allow it
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 1226
1224 # Define a customized banner (string returned when client connects) 1227 # Define a customized banner (string returned when client connects)
1225 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % 1228 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." %
1226 pyftpdlib.ftpserver.__ver__) 1229 pyftpdlib.ftpserver.__ver__)
1227 1230
1228 # Instantiate FTP server class and listen to 127.0.0.1:port 1231 # Instantiate FTP server class and listen to 127.0.0.1:port
1229 address = ('127.0.0.1', port) 1232 address = ('127.0.0.1', port)
1230 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) 1233 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler)
1231 print 'FTP server started on port %d...' % port 1234 print 'FTP server started on port %d...' % port
1232 1235
1236 # Notify the parent that we've started. (BaseServer subclasses
1237 # bind their sockets on construction.)
1238 if options.startup_pipe is not None:
1239 if sys.platform == 'win32':
1240 fd = msvcrt.open_osfhandle(options.startup_pipe, 0)
1241 else:
1242 fd = options.startup_pipe
1243 startup_pipe = os.fdopen(fd, "w")
1244 startup_pipe.write("READY")
1245 startup_pipe.close()
1246
1233 try: 1247 try:
1234 server.serve_forever() 1248 server.serve_forever()
1235 except KeyboardInterrupt: 1249 except KeyboardInterrupt:
1236 print 'shutting down server' 1250 print 'shutting down server'
1237 server.stop = True 1251 server.stop = True
1238 1252
1239 if __name__ == '__main__': 1253 if __name__ == '__main__':
1240 option_parser = optparse.OptionParser() 1254 option_parser = optparse.OptionParser()
1241 option_parser.add_option("-f", '--ftp', action='store_const', 1255 option_parser.add_option("-f", '--ftp', action='store_const',
1242 const=SERVER_FTP, default=SERVER_HTTP, 1256 const=SERVER_FTP, default=SERVER_HTTP,
(...skipping 13 matching lines...) Expand all
1256 help='Specify that the client certificate request ' 1270 help='Specify that the client certificate request '
1257 'should indicate that it supports the CA contained ' 1271 'should indicate that it supports the CA contained '
1258 'in the specified certificate file') 1272 'in the specified certificate file')
1259 option_parser.add_option('', '--file-root-url', default='/files/', 1273 option_parser.add_option('', '--file-root-url', default='/files/',
1260 help='Specify a root URL for files served.') 1274 help='Specify a root URL for files served.')
1261 option_parser.add_option('', '--never-die', default=False, 1275 option_parser.add_option('', '--never-die', default=False,
1262 action="store_true", 1276 action="store_true",
1263 help='Prevent the server from dying when visiting ' 1277 help='Prevent the server from dying when visiting '
1264 'a /kill URL. Useful for manually running some ' 1278 'a /kill URL. Useful for manually running some '
1265 'tests.') 1279 'tests.')
1280 option_parser.add_option('', '--startup-pipe', type='int',
1281 dest='startup_pipe',
1282 help='File handle of pipe to parent process')
1266 options, args = option_parser.parse_args() 1283 options, args = option_parser.parse_args()
1267 1284
1268 sys.exit(main(options, args)) 1285 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « net/test/test_server_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698