From 3aab2488b268ed3eecce12698ce92460b01283ab Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Tue, 20 Nov 2012 14:13:49 -0800 Subject: [PATCH] pep8 direct client Change-Id: I1ed6afe4336c238044174c93ae1e0078fbcef971 --- swift/common/direct_client.py | 127 +++++++++++++++++----------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 97966f510f..4078ec3348 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -74,9 +74,10 @@ def direct_get_account(node, part, account, marker=None, limit=None, if not is_success(resp.status): resp.read() raise ClientException( - 'Account server %s:%s direct GET %s gave status %s' % (node['ip'], - node['port'], repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), + 'Account server %s:%s direct GET %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), http_host=node['ip'], http_port=node['port'], http_device=node['device'], http_status=resp.status, http_reason=resp.reason) @@ -112,13 +113,13 @@ def direct_head_container(node, part, account, container, conn_timeout=5, resp.read() if not is_success(resp.status): raise ClientException( - 'Container server %s:%s direct HEAD %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Container server %s:%s direct HEAD %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) resp_headers = {} for header, value in resp.getheaders(): resp_headers[header.lower()] = value @@ -162,9 +163,10 @@ def direct_get_container(node, part, account, container, marker=None, if not is_success(resp.status): resp.read() raise ClientException( - 'Container server %s:%s direct GET %s gave stats %s' % (node['ip'], - node['port'], repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), + 'Container server %s:%s direct GET %s gave stats %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), http_host=node['ip'], http_port=node['port'], http_device=node['device'], http_status=resp.status, http_reason=resp.reason) @@ -183,19 +185,18 @@ def direct_delete_container(node, part, account, container, conn_timeout=5, headers['X-Timestamp'] = normalize_timestamp(time()) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, - 'DELETE', path, headers) + 'DELETE', path, headers) with Timeout(response_timeout): resp = conn.getresponse() resp.read() if not is_success(resp.status): raise ClientException( - 'Container server %s:%s direct DELETE %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Container server %s:%s direct DELETE %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) def direct_head_object(node, part, account, container, obj, conn_timeout=5, @@ -222,13 +223,13 @@ def direct_head_object(node, part, account, container, obj, conn_timeout=5, resp.read() if not is_success(resp.status): raise ClientException( - 'Object server %s:%s direct HEAD %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Object server %s:%s direct HEAD %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) resp_headers = {} for header, value in resp.getheaders(): resp_headers[header.lower()] = value @@ -255,19 +256,18 @@ def direct_get_object(node, part, account, container, obj, conn_timeout=5, path = '/%s/%s/%s' % (account, container, obj) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, - 'GET', path, headers=headers) + 'GET', path, headers=headers) with Timeout(response_timeout): resp = conn.getresponse() if not is_success(resp.status): resp.read() raise ClientException( - 'Object server %s:%s direct GET %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Object server %s:%s direct GET %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) if resp_chunk_size: def _object_body(): @@ -325,7 +325,7 @@ def direct_put_object(node, part, account, container, name, contents, headers['X-Timestamp'] = normalize_timestamp(time()) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, - 'PUT', path, headers=headers) + 'PUT', path, headers=headers) for chunk in contents: conn.send(chunk) with Timeout(response_timeout): @@ -333,13 +333,13 @@ def direct_put_object(node, part, account, container, name, contents, resp.read() if not is_success(resp.status): raise ClientException( - 'Object server %s:%s direct PUT %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Object server %s:%s direct PUT %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) return resp.getheader('etag').strip('"') @@ -362,23 +362,23 @@ def direct_post_object(node, part, account, container, name, headers, headers['X-Timestamp'] = normalize_timestamp(time()) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, - 'POST', path, headers=headers) + 'POST', path, headers=headers) with Timeout(response_timeout): resp = conn.getresponse() resp.read() if not is_success(resp.status): raise ClientException( - 'Object server %s:%s direct POST %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Object server %s:%s direct POST %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) def direct_delete_object(node, part, account, container, obj, - conn_timeout=5, response_timeout=15, headers={}): + conn_timeout=5, response_timeout=15, headers={}): """ Delete object directly from the object server. @@ -395,19 +395,19 @@ def direct_delete_object(node, part, account, container, obj, headers['X-Timestamp'] = normalize_timestamp(time()) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, - 'DELETE', path, headers) + 'DELETE', path, headers) with Timeout(response_timeout): resp = conn.getresponse() resp.read() if not is_success(resp.status): raise ClientException( - 'Object server %s:%s direct DELETE %s gave status %s' % - (node['ip'], node['port'], - repr('/%s/%s%s' % (node['device'], part, path)), - resp.status), - http_host=node['ip'], http_port=node['port'], - http_device=node['device'], http_status=resp.status, - http_reason=resp.reason) + 'Object server %s:%s direct DELETE %s gave status %s' % + (node['ip'], node['port'], + repr('/%s/%s%s' % (node['device'], part, path)), + resp.status), + http_host=node['ip'], http_port=node['port'], + http_device=node['device'], http_status=resp.status, + http_reason=resp.reason) def retry(func, *args, **kwargs): @@ -453,7 +453,8 @@ def retry(func, *args, **kwargs): # Shouldn't actually get down here, but just in case. if args and 'ip' in args[0]: raise ClientException('Raise too many retries', - http_host=args[0]['ip'], http_port=args[0]['port'], - http_device=args[0]['device']) + http_host=args[ + 0]['ip'], http_port=args[0]['port'], + http_device=args[0]['device']) else: raise ClientException('Raise too many retries')