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

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

Issue 11191047: Upstream Android-specific net/ changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove message loop thread check Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_service.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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/FTP/SYNC/TCP/UDP/ server used for testing Chrome. 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ 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
(...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 return False 1963 return False
1964 result, raw_reply = self.server._sync_handler.HandleCreateSyncedBookmarks() 1964 result, raw_reply = self.server._sync_handler.HandleCreateSyncedBookmarks()
1965 self.send_response(result) 1965 self.send_response(result)
1966 self.send_header('Content-Type', 'text/html') 1966 self.send_header('Content-Type', 'text/html')
1967 self.send_header('Content-Length', len(raw_reply)) 1967 self.send_header('Content-Length', len(raw_reply))
1968 self.end_headers() 1968 self.end_headers()
1969 self.wfile.write(raw_reply) 1969 self.wfile.write(raw_reply)
1970 return True; 1970 return True;
1971 1971
1972 1972
1973 def MakeDataDir(): 1973 def MakeDataDir(options):
1974 if options.data_dir: 1974 if options.data_dir:
1975 if not os.path.isdir(options.data_dir): 1975 if not os.path.isdir(options.data_dir):
1976 print 'specified data dir not found: ' + options.data_dir + ' exiting...' 1976 print 'specified data dir not found: ' + options.data_dir + ' exiting...'
1977 return None 1977 return None
1978 my_data_dir = options.data_dir 1978 my_data_dir = options.data_dir
1979 else: 1979 else:
1980 # Create the default path to our data dir, relative to the exe dir. 1980 # Create the default path to our data dir, relative to the exe dir.
1981 my_data_dir = os.path.dirname(sys.argv[0]) 1981 my_data_dir = os.path.dirname(sys.argv[0])
1982 my_data_dir = os.path.join(my_data_dir, "..", "..", "..", "..", 1982 my_data_dir = os.path.join(my_data_dir, "..", "..", "..", "..",
1983 "test", "data") 1983 "test", "data")
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 self.__fd2.close() 2169 self.__fd2.close()
2170 2170
2171 def write(self, text) : 2171 def write(self, text) :
2172 self.__fd1.write(text) 2172 self.__fd1.write(text)
2173 self.__fd2.write(text) 2173 self.__fd2.write(text)
2174 2174
2175 def flush(self) : 2175 def flush(self) :
2176 self.__fd1.flush() 2176 self.__fd1.flush()
2177 self.__fd2.flush() 2177 self.__fd2.flush()
2178 2178
2179 def close(self):
2180 """Add this only for disabling error message from python because
2181 FileMultiplexer acts as File Object, and File Object in python has
2182 close method"""
2183 pass
Paweł Hajdan Jr. 2012/10/18 19:14:44 Why don't we close our fds here like in __del__ ?
newt (away) 2012/10/18 20:54:34 Done.
2184
2185
2179 def main(options, args): 2186 def main(options, args):
2180 logfile = open('testserver.log', 'w') 2187 logfile = open('testserver.log', 'w')
2181 sys.stderr = FileMultiplexer(sys.stderr, logfile) 2188 sys.stderr = FileMultiplexer(sys.stderr, logfile)
2182 if options.log_to_console: 2189 if options.log_to_console:
2183 sys.stdout = FileMultiplexer(sys.stdout, logfile) 2190 sys.stdout = FileMultiplexer(sys.stdout, logfile)
2184 else: 2191 else:
2185 sys.stdout = logfile 2192 sys.stdout = logfile
2186 2193
2187 port = options.port 2194 port = options.port
2188 host = options.host 2195 host = options.host
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 return 2247 return
2241 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, 2248 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key,
2242 options.ssl_client_auth, options.ssl_client_ca, 2249 options.ssl_client_auth, options.ssl_client_ca,
2243 options.ssl_bulk_cipher, options.record_resume, 2250 options.ssl_bulk_cipher, options.record_resume,
2244 options.tls_intolerant) 2251 options.tls_intolerant)
2245 print 'HTTPS server started on %s:%d...' % (host, server.server_port) 2252 print 'HTTPS server started on %s:%d...' % (host, server.server_port)
2246 else: 2253 else:
2247 server = HTTPServer((host, port), TestPageHandler) 2254 server = HTTPServer((host, port), TestPageHandler)
2248 print 'HTTP server started on %s:%d...' % (host, server.server_port) 2255 print 'HTTP server started on %s:%d...' % (host, server.server_port)
2249 2256
2250 server.data_dir = MakeDataDir() 2257 server.data_dir = MakeDataDir(options)
2251 server.file_root_url = options.file_root_url 2258 server.file_root_url = options.file_root_url
2252 server_data['port'] = server.server_port 2259 server_data['port'] = server.server_port
2253 server._device_management_handler = None 2260 server._device_management_handler = None
2254 server.policy_keys = options.policy_keys 2261 server.policy_keys = options.policy_keys
2255 server.policy_user = options.policy_user 2262 server.policy_user = options.policy_user
2256 server.gdata_auth_token = options.auth_token 2263 server.gdata_auth_token = options.auth_token
2257 elif options.server_type == SERVER_WEBSOCKET: 2264 elif options.server_type == SERVER_WEBSOCKET:
2258 # Launch pywebsocket via WebSocketServer. 2265 # Launch pywebsocket via WebSocketServer.
2259 logger = logging.getLogger() 2266 logger = logging.getLogger()
2260 logger.addHandler(logging.StreamHandler()) 2267 logger.addHandler(logging.StreamHandler())
(...skipping 23 matching lines...) Expand all
2284 random.seed() 2291 random.seed()
2285 server = UDPEchoServer((host, port), UDPEchoHandler) 2292 server = UDPEchoServer((host, port), UDPEchoHandler)
2286 print 'Echo UDP server started on port %d...' % server.server_port 2293 print 'Echo UDP server started on port %d...' % server.server_port
2287 server_data['port'] = server.server_port 2294 server_data['port'] = server.server_port
2288 elif options.server_type == SERVER_BASIC_AUTH_PROXY: 2295 elif options.server_type == SERVER_BASIC_AUTH_PROXY:
2289 server = HTTPServer((host, port), BasicAuthProxyRequestHandler) 2296 server = HTTPServer((host, port), BasicAuthProxyRequestHandler)
2290 print 'BasicAuthProxy server started on port %d...' % server.server_port 2297 print 'BasicAuthProxy server started on port %d...' % server.server_port
2291 server_data['port'] = server.server_port 2298 server_data['port'] = server.server_port
2292 # means FTP Server 2299 # means FTP Server
2293 else: 2300 else:
2294 my_data_dir = MakeDataDir() 2301 my_data_dir = MakeDataDir(options)
2295 2302
2296 # Instantiate a dummy authorizer for managing 'virtual' users 2303 # Instantiate a dummy authorizer for managing 'virtual' users
2297 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() 2304 authorizer = pyftpdlib.ftpserver.DummyAuthorizer()
2298 2305
2299 # Define a new user having full r/w permissions and a read-only 2306 # Define a new user having full r/w permissions and a read-only
2300 # anonymous user 2307 # anonymous user
2301 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') 2308 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw')
2302 2309
2303 authorizer.add_anonymous(my_data_dir) 2310 authorizer.add_anonymous(my_data_dir)
2304 2311
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 dest='host', 2454 dest='host',
2448 help='Hostname or IP upon which the server will ' 2455 help='Hostname or IP upon which the server will '
2449 'listen. Client connections will also only be ' 2456 'listen. Client connections will also only be '
2450 'allowed from this address.') 2457 'allowed from this address.')
2451 option_parser.add_option('', '--auth-token', dest='auth_token', 2458 option_parser.add_option('', '--auth-token', dest='auth_token',
2452 help='Specify the auth token which should be used' 2459 help='Specify the auth token which should be used'
2453 'in the authorization header for GData.') 2460 'in the authorization header for GData.')
2454 options, args = option_parser.parse_args() 2461 options, args = option_parser.parse_args()
2455 2462
2456 sys.exit(main(options, args)) 2463 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698