Merge "Report path information in failure exceptions"
This commit is contained in:
commit
04f3a4e4bd
@ -40,16 +40,19 @@ class RequestError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class ResponseError(Exception):
|
class ResponseError(Exception):
|
||||||
def __init__(self, response):
|
def __init__(self, response, method, path):
|
||||||
self.status = response.status
|
self.status = response.status
|
||||||
self.reason = response.reason
|
self.reason = response.reason
|
||||||
Exception.__init__(self)
|
self.method = method
|
||||||
|
self.path = path
|
||||||
|
super(ResponseError, self).__init__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%d: %s' % (self.status, self.reason)
|
return repr(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%d: %s' % (self.status, self.reason)
|
return '%d: %r (%r %r)' % (self.status, self.reason, self.method,
|
||||||
|
self.path)
|
||||||
|
|
||||||
|
|
||||||
def listing_empty(method):
|
def listing_empty(method):
|
||||||
@ -352,7 +355,8 @@ class Account(Base):
|
|||||||
elif status == 204:
|
elif status == 204:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'GET',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
def delete_containers(self):
|
def delete_containers(self):
|
||||||
for c in listing_items(self.containers):
|
for c in listing_items(self.containers):
|
||||||
@ -366,7 +370,8 @@ class Account(Base):
|
|||||||
if self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
if self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
||||||
parms=parms, cfg=cfg) != 204:
|
parms=parms, cfg=cfg) != 204:
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'HEAD',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
fields = [['object_count', 'x-account-object-count'],
|
fields = [['object_count', 'x-account-object-count'],
|
||||||
['container_count', 'x-account-container-count'],
|
['container_count', 'x-account-container-count'],
|
||||||
@ -454,7 +459,8 @@ class Container(Base):
|
|||||||
elif status == 204:
|
elif status == 204:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'GET',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
def info(self, hdrs={}, parms={}, cfg={}):
|
def info(self, hdrs={}, parms={}, cfg={}):
|
||||||
self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
||||||
@ -466,7 +472,8 @@ class Container(Base):
|
|||||||
|
|
||||||
return self.header_fields(fields)
|
return self.header_fields(fields)
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'HEAD',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
@ -541,7 +548,8 @@ class File(Base):
|
|||||||
if self.conn.make_request('DELETE', self.path, hdrs=hdrs,
|
if self.conn.make_request('DELETE', self.path, hdrs=hdrs,
|
||||||
parms=parms) != 204:
|
parms=parms) != 204:
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'DELETE',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -549,7 +557,8 @@ class File(Base):
|
|||||||
if self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
if self.conn.make_request('HEAD', self.path, hdrs=hdrs,
|
||||||
parms=parms, cfg=cfg) != 200:
|
parms=parms, cfg=cfg) != 200:
|
||||||
|
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'HEAD',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
fields = [['content_length', 'content-length'],
|
fields = [['content_length', 'content-length'],
|
||||||
['content_type', 'content-type'],
|
['content_type', 'content-type'],
|
||||||
@ -569,7 +578,8 @@ class File(Base):
|
|||||||
if status == 404:
|
if status == 404:
|
||||||
return False
|
return False
|
||||||
elif (status < 200) or (status > 299):
|
elif (status < 200) or (status > 299):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'HEAD',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
for hdr in self.conn.response.getheaders():
|
for hdr in self.conn.response.getheaders():
|
||||||
if hdr[0].lower() == 'content-type':
|
if hdr[0].lower() == 'content-type':
|
||||||
@ -616,8 +626,9 @@ class File(Base):
|
|||||||
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
||||||
cfg=cfg, parms=parms)
|
cfg=cfg, parms=parms)
|
||||||
|
|
||||||
if(status < 200) or (status > 299):
|
if (status < 200) or (status > 299):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'GET',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
for hdr in self.conn.response.getheaders():
|
for hdr in self.conn.response.getheaders():
|
||||||
if hdr[0].lower() == 'content-type':
|
if hdr[0].lower() == 'content-type':
|
||||||
@ -640,8 +651,9 @@ class File(Base):
|
|||||||
def read_md5(self):
|
def read_md5(self):
|
||||||
status = self.conn.make_request('GET', self.path)
|
status = self.conn.make_request('GET', self.path)
|
||||||
|
|
||||||
if(status < 200) or (status > 299):
|
if (status < 200) or (status > 299):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'GET',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
checksum = hashlib.md5()
|
checksum = hashlib.md5()
|
||||||
|
|
||||||
@ -674,7 +686,8 @@ class File(Base):
|
|||||||
self.conn.make_request('POST', self.path, hdrs=headers, cfg=cfg)
|
self.conn.make_request('POST', self.path, hdrs=headers, cfg=cfg)
|
||||||
|
|
||||||
if self.conn.response.status not in (201, 202):
|
if self.conn.response.status not in (201, 202):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'POST',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -732,7 +745,8 @@ class File(Base):
|
|||||||
|
|
||||||
if (self.conn.response.status < 200) or \
|
if (self.conn.response.status < 200) or \
|
||||||
(self.conn.response.status > 299):
|
(self.conn.response.status > 299):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'PUT',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
@ -745,6 +759,7 @@ class File(Base):
|
|||||||
def write_random(self, size=None, hdrs={}, parms={}, cfg={}):
|
def write_random(self, size=None, hdrs={}, parms={}, cfg={}):
|
||||||
data = self.random_data(size)
|
data = self.random_data(size)
|
||||||
if not self.write(data, hdrs=hdrs, parms=parms, cfg=cfg):
|
if not self.write(data, hdrs=hdrs, parms=parms, cfg=cfg):
|
||||||
raise ResponseError(self.conn.response)
|
raise ResponseError(self.conn.response, 'PUT',
|
||||||
|
self.conn.make_path(self.path))
|
||||||
self.md5 = self.compute_md5sum(StringIO.StringIO(data))
|
self.md5 = self.compute_md5sum(StringIO.StringIO(data))
|
||||||
return data
|
return data
|
||||||
|
Loading…
Reference in New Issue
Block a user