Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 267 lines (221 sloc) 8.027 kb
c626a933 » Mitch.Garnaat
2007-01-08 Modified copyright on all files. Also fixed a bug in the EC2 Security…
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
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
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
22 """
23 Exception classes - Subclassing allows you to check for specific errors
24 """
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
25
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
26 from boto import handler
27 from boto.resultset import ResultSet
28
29 import xml.sax
30
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
31 class BotoClientError(Exception):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
32 """
33 General Boto Client error (error accessing AWS)
34 """
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
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
17795048 » Mitch.Garnaat
2007-12-09 Adding convenience methods to S3 module to make it easier to add gran…
44
881c3ba5 » Mitch.Garnaat
2008-05-27 Fixing lingering typo in Exception class.
45 class SDBPersistenceError(Exception):
8eed3844 » Mitch.Garnaat
2008-01-07 Adding an exception for the SDB persistance stuff
46
47 pass
48
17795048 » Mitch.Garnaat
2007-12-09 Adding convenience methods to S3 module to make it easier to add gran…
49 class S3PermissionsError(BotoClientError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
50 """
51 Permissions error when accessing a bucket or key on S3.
52 """
17795048 » Mitch.Garnaat
2007-12-09 Adding convenience methods to S3 module to make it easier to add gran…
53 pass
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
54
55 class BotoServerError(Exception):
56
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
57 def __init__(self, status, reason, body=None):
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
58 self.status = status
59 self.reason = reason
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
60 self.body = body or ''
61 self.request_id = None
11dfdd01 » Mitch.Garnaat
2009-04-09 Added some additional attributes to BotoServerError. fixes issue 218.
62 self.error_code = None
63 self.error_message = None
64 self.box_usage = None
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
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()
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
78
79 def __repr__(self):
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
80 return '%s: %s %s\n%s' % (self.__class__.__name__,
81 self.status, self.reason, self.body)
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
82
83 def __str__(self):
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
84 return '%s: %s %s\n%s' % (self.__class__.__name__,
85 self.status, self.reason, self.body)
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
86
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
87 def startElement(self, name, attrs, connection):
88 pass
89
90 def endElement(self, name, value, connection):
91 if name in ('RequestId', 'RequestID'):
92 self.request_id = value
11dfdd01 » Mitch.Garnaat
2009-04-09 Added some additional attributes to BotoServerError. fixes issue 218.
93 elif name == 'Code':
94 self.code = value
95 elif name == 'Message':
96 self.message = value
97 elif name == 'BoxUsage':
98 self.box_usage = value
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
99 return None
100
101 def _cleanupParsedProperties(self):
102 self.request_id = None
103
104
105 class ConsoleOutput:
106
107 def __init__(self, parent=None):
108 self.parent = parent
109 self.instance_id = None
110 self.timestamp = None
111 self.comment = None
112
113 def startElement(self, name, attrs, connection):
114 return None
115
116 def endElement(self, name, value, connection):
117 if name == 'instanceId':
118 self.instance_id = value
119 elif name == 'output':
120 self.output = base64.b64decode(value)
121 else:
122 setattr(self, name, value)
123
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
124 class S3CreateError(BotoServerError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
125 """
126 Error creating a bucket or key on S3.
127 """
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
128 pass
129
c59fe9d3 » Mitch.Garnaat
2008-05-03 Initial implementation of the new COPY method, currently available vi…
130 class S3CopyError(BotoServerError):
131 """
132 Error copying a key on S3.
133 """
134 pass
135
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
136 class SQSError(BotoServerError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
137 """
138 General Error on Simple Queue Service.
139 """
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
140 def __init__(self, status, reason, body=None):
141 self.detail = None
142 self.type = None
143 self.code = None
144 self.message = None
145 BotoServerError.__init__(self, status, reason, body)
146
147 def startElement(self, name, attrs, connection):
148 return BotoServerError.startElement(self, name, attrs, connection)
149
150 def endElement(self, name, value, connection):
151 if name == 'Detail':
152 self.detail = value
153 elif name == 'Type':
154 self.type = value
155 elif name == 'Code':
156 self.code = value
157 elif name == 'Message':
158 self.message = value
159 else:
160 return BotoServerError.endElement(self, name, value, connection)
161
162 def _cleanupParsedProperties(self):
163 BotoServerError._cleanupParsedProperties(self)
164 for p in ('detail', 'type', 'code', 'message'):
165 setattr(self, p, None)
166
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
167 class S3ResponseError(BotoServerError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
168 """
169 Error in response from S3.
170 """
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
171 def __init__(self, status, reason, body=None):
172 self.resource = None
173 self.code = None
174 self.message = None
175 BotoServerError.__init__(self, status, reason, body)
176
177 def startElement(self, name, attrs, connection):
178 return BotoServerError.startElement(self, name, attrs, connection)
179
180 def endElement(self, name, value, connection):
181 if name == 'Resource':
182 self.resource = value
183 elif name == 'Code':
184 self.code = value
185 elif name == 'Message':
186 self.message = value
187 else:
188 return BotoServerError.endElement(self, name, value, connection)
189
190 def _cleanupParsedProperties(self):
191 BotoServerError._cleanupParsedProperties(self)
192 for p in ('resource', 'code', 'message'):
193 setattr(self, p, None)
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
194
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
195 class EC2ResponseError(BotoServerError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
196 """
197 Error in response from EC2.
198 """
f77a063b » Mitch.Garnaat
2008-08-24 Incorporating a patch to parse the XML error responses. Fixes Issue-151.
199
200 def __init__(self, status, reason, body=None):
201 self.code = None
202 self.message = None
203 self.errors = None
204 self._errorResultSet = []
205 BotoServerError.__init__(self, status, reason, body)
206 self.errors = [ (e.code, e.message) \
207 for e in self._errorResultSet ]
208 if len(self.errors):
209 self.code, self.message = self.errors[0]
210
211 def startElement(self, name, attrs, connection):
212 if name == 'Errors':
213 self._errorResultSet = ResultSet([('Error', _EC2Error)])
214 return self._errorResultSet
215 else:
216 return None
217
218 def endElement(self, name, value, connection):
219 if name == 'RequestID':
220 self.request_id = value
221 else:
222 return None # don't call subclass here
223
224 def _cleanupParsedProperties(self):
225 BotoServerError._cleanupParsedProperties(self)
226 self._errorResultSet = []
227 for p in ('errors', 'code', 'message'):
228 setattr(self, p, None)
229
230 class _EC2Error:
231
232 def __init__(self, connection=None):
233 self.connection = connection
234 self.code = None
235 self.message = None
236
237 def startElement(self, name, attrs, connection):
238 return None
239
240 def endElement(self, name, value, connection):
241 if name == 'Code':
242 self.code = value
243 elif name == 'Message':
244 self.message = value
245 else:
246 return None
5d5aa35d » Mitch.Garnaat
2006-08-27 Initial version of code. Still not complete for correct but passes si…
247
ef8cef7f » Mitch.Garnaat
2007-12-21 Snapshot of SDB code that works with API version released with public…
248 class SDBResponseError(BotoServerError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
249 """
250 Error in respones from SDB.
251 """
ef8cef7f » Mitch.Garnaat
2007-12-21 Snapshot of SDB code that works with API version released with public…
252 pass
253
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
254 class AWSConnectionError(BotoClientError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
255 """
256 General error connecting to Amazon Web Services.
257 """
49e96128 » Mitch.Garnaat
2007-01-17 Added explicit mimetype override for uploaded files, Fixes Issue-25. …
258 pass
86f13735 » Mitch.Garnaat
2007-02-08 Merged in changes from David Strip to support proxy servers for non-S…
259
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
260 class S3DataError(BotoClientError):
0496c1f7 » jgeewax
2008-04-20 General docs on the boto exceptions.
261 """
262 Error receiving data from S3.
263 """
238451a4 » Mitch.Garnaat
2007-06-21 Trying to make more sense of the exceptions.
264 pass
86f13735 » Mitch.Garnaat
2007-02-08 Merged in changes from David Strip to support proxy servers for non-S…
265
ed1afa40 » kopertop
2008-02-27 Added some FPS support
266 class FPSResponseError(BotoServerError):
267 pass
Something went wrong with that request. Please try again.