/
Exceptions.py
46 lines (37 loc) · 1.16 KB
/
Exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Amazon S3 manager - Exceptions library
## Author: Michal Ludvig <michal@logix.cz>
## http://www.logix.cz/michal
## License: GPL Version 2
from logging import debug, info, warning, error
try:
import xml.etree.ElementTree as ET
except ImportError:
import elementtree.ElementTree as ET
class S3Error (Exception):
def __init__(self, response):
self.status = response["status"]
self.reason = response["reason"]
self.info = {}
debug("S3Error: %s (%s)" % (self.status, self.reason))
if response.has_key("headers"):
for header in response["headers"]:
debug("HttpHeader: %s: %s" % (header, response["headers"][header]))
if response.has_key("data"):
tree = ET.fromstring(response["data"])
for child in tree.getchildren():
if child.text != "":
debug("ErrorXML: " + child.tag + ": " + repr(child.text))
self.info[child.tag] = child.text
def __str__(self):
retval = "%d (%s)" % (self.status, self.reason)
try:
retval += (": %s" % self.info["Code"])
except (AttributeError, KeyError):
pass
return retval
class S3UploadError(Exception):
pass
class S3DownloadError(Exception):
pass
class ParameterError(Exception):
pass