minutæ: port ClientException tweaks from swiftclient; dict .pop

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
This commit is contained in:
Zack M. Davis 2015-10-08 16:16:18 -07:00
parent 6a9b868ae6
commit 1ba7641c79
2 changed files with 4 additions and 10 deletions

View File

@ -513,14 +513,8 @@ def retry(func, *args, **kwargs):
:returns: result of func :returns: result of func
:raises ClientException: all retries failed :raises ClientException: all retries failed
""" """
retries = 5 retries = kwargs.pop('retries', 5)
if 'retries' in kwargs: error_log = kwargs.pop('error_log', None)
retries = kwargs['retries']
del kwargs['retries']
error_log = None
if 'error_log' in kwargs:
error_log = kwargs['error_log']
del kwargs['error_log']
attempts = 0 attempts = 0
backoff = 1 backoff = 1
while attempts <= retries: while attempts <= retries:

View File

@ -214,9 +214,9 @@ class APIVersionError(SwiftException):
class ClientException(Exception): class ClientException(Exception):
def __init__(self, msg, http_scheme='', http_host='', http_port='', 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): http_device='', http_response_content='', http_headers=None):
Exception.__init__(self, msg) super(ClientException, self).__init__(msg)
self.msg = msg self.msg = msg
self.http_scheme = http_scheme self.http_scheme = http_scheme
self.http_host = http_host self.http_host = http_host