Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (223 sloc) 8.248 kB
c626a93 Modified copyright on all files. Also fixed a bug in the EC2 Securit…
Mitch.Garnaat authored
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
0496c1f General docs on the boto exceptions.
jgeewax authored
22 """
23 Exception classes - Subclassing allows you to check for specific errors
24 """
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
25
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
26 from boto import handler
27 from boto.resultset import ResultSet
28
29 import xml.sax
30
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
31 class BotoClientError(Exception):
0496c1f General docs on the boto exceptions.
jgeewax authored
32 """
33 General Boto Client error (error accessing AWS)
34 """
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
35
36 def __init__(self, reason):
37 self.reason = reason
38
39 def __repr__(self):
40 return 'S3Error: %s' % self.reason
41
42 def __str__(self):
43 return 'S3Error: %s' % self.reason
1779504 Adding convenience methods to S3 module to make it easier to add gran…
Mitch.Garnaat authored
44
881c3ba Fixing lingering typo in Exception class.
Mitch.Garnaat authored
45 class SDBPersistenceError(Exception):
8eed384 Adding an exception for the SDB persistance stuff
Mitch.Garnaat authored
46
47 pass
48
1779504 Adding convenience methods to S3 module to make it easier to add gran…
Mitch.Garnaat authored
49 class S3PermissionsError(BotoClientError):
0496c1f General docs on the boto exceptions.
jgeewax authored
50 """
51 Permissions error when accessing a bucket or key on S3.
52 """
1779504 Adding convenience methods to S3 module to make it easier to add gran…
Mitch.Garnaat authored
53 pass
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
54
55 class BotoServerError(Exception):
56
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
57 def __init__(self, status, reason, body=None):
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
58 self.status = status
59 self.reason = reason
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
60 self.body = body or ''
61 self.request_id = None
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
62 self.error_code = None
63 self.error_message = None
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
64 self.box_usage = None
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
65
66 # Attempt to parse the error response. If body isn't present,
67 # then just ignore the error response.
68 if self.body:
69 try:
70 h = handler.XmlHandler(self, self)
71 xml.sax.parseString(self.body, h)
72 except xml.sax.SAXParseException, pe:
73 # Go ahead and clean up anything that may have
74 # managed to get into the error data so we
75 # don't get partial garbage.
76 print "Warning: failed to parse error message from AWS: %s" % pe
77 self._cleanupParsedProperties()
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
78
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
79 def __getattr__(self, name):
80 if name == 'message':
81 return self.error_message
82 if name == 'code':
83 return self.error_code
84 raise AttributeError
85
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
86 def __repr__(self):
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
87 return '%s: %s %s\n%s' % (self.__class__.__name__,
88 self.status, self.reason, self.body)
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
89
90 def __str__(self):
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
91 return '%s: %s %s\n%s' % (self.__class__.__name__,
92 self.status, self.reason, self.body)
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
93
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
94 def startElement(self, name, attrs, connection):
95 pass
96
97 def endElement(self, name, value, connection):
98 if name in ('RequestId', 'RequestID'):
99 self.request_id = value
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
100 elif name == 'Code':
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
101 self.error_code = value
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
102 elif name == 'Message':
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
103 self.error_message = value
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
104 elif name == 'BoxUsage':
105 self.box_usage = value
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
106 return None
107
108 def _cleanupParsedProperties(self):
109 self.request_id = None
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
110 self.error_code = None
111 self.error_message = None
112 self.box_usage = None
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
113
114 class ConsoleOutput:
115
116 def __init__(self, parent=None):
117 self.parent = parent
118 self.instance_id = None
119 self.timestamp = None
120 self.comment = None
121
122 def startElement(self, name, attrs, connection):
123 return None
124
125 def endElement(self, name, value, connection):
126 if name == 'instanceId':
127 self.instance_id = value
128 elif name == 'output':
129 self.output = base64.b64decode(value)
130 else:
131 setattr(self, name, value)
132
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
133 class S3CreateError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
134 """
135 Error creating a bucket or key on S3.
136 """
9a4403a Fixed bug in last commit and also fixed issue 204.
Mitch.Garnaat authored
137 def __init__(self, status, reason, body=None):
138 self.bucket = None
139 BotoServerError.__init__(self, status, reason, body)
140
141 def endElement(self, name, value, connection):
142 if name == 'BucketName':
143 self.bucket = value
144 else:
145 return BotoServerError.endElement(self, name, value, connection)
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
146
c59fe9d Initial implementation of the new COPY method, currently available vi…
Mitch.Garnaat authored
147 class S3CopyError(BotoServerError):
148 """
149 Error copying a key on S3.
150 """
151 pass
152
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
153 class SQSError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
154 """
155 General Error on Simple Queue Service.
156 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
157 def __init__(self, status, reason, body=None):
158 self.detail = None
159 self.type = None
160 BotoServerError.__init__(self, status, reason, body)
161
162 def startElement(self, name, attrs, connection):
163 return BotoServerError.startElement(self, name, attrs, connection)
164
165 def endElement(self, name, value, connection):
166 if name == 'Detail':
167 self.detail = value
168 elif name == 'Type':
169 self.type = value
170 else:
171 return BotoServerError.endElement(self, name, value, connection)
172
173 def _cleanupParsedProperties(self):
174 BotoServerError._cleanupParsedProperties(self)
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
175 for p in ('detail', 'type'):
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
176 setattr(self, p, None)
177
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
178 class S3ResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
179 """
180 Error in response from S3.
181 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
182 def __init__(self, status, reason, body=None):
183 self.resource = None
184 BotoServerError.__init__(self, status, reason, body)
185
186 def startElement(self, name, attrs, connection):
187 return BotoServerError.startElement(self, name, attrs, connection)
188
189 def endElement(self, name, value, connection):
190 if name == 'Resource':
191 self.resource = value
192 else:
193 return BotoServerError.endElement(self, name, value, connection)
194
195 def _cleanupParsedProperties(self):
196 BotoServerError._cleanupParsedProperties(self)
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
197 for p in ('resource'):
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
198 setattr(self, p, None)
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
199
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
200 class EC2ResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
201 """
202 Error in response from EC2.
203 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
204
205 def __init__(self, status, reason, body=None):
206 self.errors = None
207 self._errorResultSet = []
208 BotoServerError.__init__(self, status, reason, body)
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
209 self.errors = [ (e.error_code, e.error_message) \
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
210 for e in self._errorResultSet ]
211 if len(self.errors):
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
212 self.error_code, self.error_message = self.errors[0]
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
213
214 def startElement(self, name, attrs, connection):
215 if name == 'Errors':
216 self._errorResultSet = ResultSet([('Error', _EC2Error)])
217 return self._errorResultSet
218 else:
219 return None
220
221 def endElement(self, name, value, connection):
222 if name == 'RequestID':
223 self.request_id = value
224 else:
225 return None # don't call subclass here
226
227 def _cleanupParsedProperties(self):
228 BotoServerError._cleanupParsedProperties(self)
229 self._errorResultSet = []
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
230 for p in ('errors'):
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
231 setattr(self, p, None)
232
233 class _EC2Error:
234
235 def __init__(self, connection=None):
236 self.connection = connection
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
237 self.error_code = None
238 self.error_message = None
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
239
240 def startElement(self, name, attrs, connection):
241 return None
242
243 def endElement(self, name, value, connection):
244 if name == 'Code':
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
245 self.error_code = value
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
246 elif name == 'Message':
7bd8aae Trying to normalize the exceptions a bit and also remove deprecated r…
Mitch.Garnaat authored
247 self.error_message = value
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-…
Mitch.Garnaat authored
248 else:
249 return None
5d5aa35 Initial version of code. Still not complete for correct but passes s…
Mitch.Garnaat authored
250
ef8cef7 Snapshot of SDB code that works with API version released with public…
Mitch.Garnaat authored
251 class SDBResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
252 """
253 Error in respones from SDB.
254 """
ef8cef7 Snapshot of SDB code that works with API version released with public…
Mitch.Garnaat authored
255 pass
256
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
257 class AWSConnectionError(BotoClientError):
0496c1f General docs on the boto exceptions.
jgeewax authored
258 """
259 General error connecting to Amazon Web Services.
260 """
49e9612 Added explicit mimetype override for uploaded files, Fixes Issue-25. …
Mitch.Garnaat authored
261 pass
86f1373 Merged in changes from David Strip to support proxy servers for non-S…
Mitch.Garnaat authored
262
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
263 class S3DataError(BotoClientError):
0496c1f General docs on the boto exceptions.
jgeewax authored
264 """
265 Error receiving data from S3.
266 """
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
267 pass
86f1373 Merged in changes from David Strip to support proxy servers for non-S…
Mitch.Garnaat authored
268
ed1afa4 Added some FPS support
kopertop authored
269 class FPSResponseError(BotoServerError):
270 pass
Something went wrong with that request. Please try again.