diff options
Diffstat (limited to 'catapult/devil/devil/android/ports.py')
-rw-r--r-- | catapult/devil/devil/android/ports.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/catapult/devil/devil/android/ports.py b/catapult/devil/devil/android/ports.py index 4547a627..f25c8bfd 100644 --- a/catapult/devil/devil/android/ports.py +++ b/catapult/devil/devil/android/ports.py @@ -1,7 +1,6 @@ # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. - """Functions that deal with local and device ports.""" import contextlib @@ -63,8 +62,7 @@ def AllocateTestServerPort(): while not IsHostPortAvailable(port): port += 1 ports_tried.append(port) - if (port > _TEST_SERVER_PORT_LAST or - port < _TEST_SERVER_PORT_FIRST): + if port > _TEST_SERVER_PORT_LAST or port < _TEST_SERVER_PORT_FIRST: port = 0 else: fp.seek(0, os.SEEK_SET) @@ -78,8 +76,9 @@ def AllocateTestServerPort(): if port: logger.info('Allocate port %d for test server.', port) else: - logger.error('Could not allocate port for test server. ' - 'List of ports tried: %s', str(ports_tried)) + logger.error( + 'Could not allocate port for test server. ' + 'List of ports tried: %s', str(ports_tried)) return port @@ -115,8 +114,9 @@ def IsDevicePortUsed(device, device_port, state=''): True if the port on device is already used, otherwise returns False. """ base_urls = ('127.0.0.1:%d' % device_port, 'localhost:%d' % device_port) - netstat_results = device.RunShellCommand( - ['netstat', '-an'], check_return=True, large_output=True) + netstat_results = device.RunShellCommand(['netstat', '-an'], + check_return=True, + large_output=True) for single_connect in netstat_results: # Column 3 is the local address which we want to check with. connect_results = single_connect.split() @@ -131,8 +131,13 @@ def IsDevicePortUsed(device, device_port, state=''): return False -def IsHttpServerConnectable(host, port, tries=3, command='GET', path='/', - expected_read='', timeout=2): +def IsHttpServerConnectable(host, + port, + tries=3, + command='GET', + path='/', + expected_read='', + timeout=2): """Checks whether the specified http server is ready to serve request or not. Args: @@ -157,8 +162,8 @@ def IsHttpServerConnectable(host, port, tries=3, command='GET', path='/', for i in xrange(0, tries): client_error = None try: - with contextlib.closing(httplib.HTTPConnection( - host, port, timeout=timeout)) as http: + with contextlib.closing( + httplib.HTTPConnection(host, port, timeout=timeout)) as http: # Output some debug information when we have tried more than 2 times. http.set_debuglevel(i >= 2) http.request(command, path) @@ -167,8 +172,8 @@ def IsHttpServerConnectable(host, port, tries=3, command='GET', path='/', if r.status == 200 and r.reason == 'OK' and content == expected_read: return (True, '') client_error = ('Bad response: %s %s version %s\n ' % - (r.status, r.reason, r.version) + - '\n '.join([': '.join(h) for h in r.getheaders()])) + (r.status, r.reason, r.version) + '\n '.join( + [': '.join(h) for h in r.getheaders()])) except (httplib.HTTPException, socket.error) as e: # Probably too quick connecting: try again. exception_error_msgs = traceback.format_exception_only(type(e), e) |