From 1ba7641c794104de57e5010f76cecbf146a2a63b Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 8 Oct 2015 16:16:18 -0700 Subject: [PATCH] =?UTF-8?q?minut=C3=A6:=20port=20ClientException=20tweaks?= =?UTF-8?q?=20from=20swiftclient;=20dict=20.pop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openstack/python-swiftclient@5ae4b423 changed python-swiftclient's ClientException to have its http_status attribute default to None (rather than 0) and to use super in its __init__ method. For consistency's sake, it's nice for Swift's inlined copy of ClientException to receive the same patch. Also, the retry function in direct_client (a major user of ClientException) was using a somewhat awkward conditional-assignment-and-delete construction where the .pop method of dictionaries would be more idiomatic. Change-Id: I70a12f934f84f57549617af28b86f7f5637bd8fa --- swift/common/direct_client.py | 10 ++-------- swift/common/exceptions.py | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 3058309b8b..db7c48aa7e 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -513,14 +513,8 @@ def retry(func, *args, **kwargs): :returns: result of func :raises ClientException: all retries failed """ - retries = 5 - if 'retries' in kwargs: - retries = kwargs['retries'] - del kwargs['retries'] - error_log = None - if 'error_log' in kwargs: - error_log = kwargs['error_log'] - del kwargs['error_log'] + retries = kwargs.pop('retries', 5) + error_log = kwargs.pop('error_log', None) attempts = 0 backoff = 1 while attempts <= retries: diff --git a/swift/common/exceptions.py b/swift/common/exceptions.py index 54b4e2e2ea..2f36ab623d 100644 --- a/swift/common/exceptions.py +++ b/swift/common/exceptions.py @@ -214,9 +214,9 @@ class APIVersionError(SwiftException): class ClientException(Exception): def __init__(self, msg, http_scheme='', http_host='', http_port='', - http_path='', http_query='', http_status=0, http_reason='', + http_path='', http_query='', http_status=None, http_reason='', http_device='', http_response_content='', http_headers=None): - Exception.__init__(self, msg) + super(ClientException, self).__init__(msg) self.msg = msg self.http_scheme = http_scheme self.http_host = http_host