Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 268 lines (221 sloc) 8.027 kb
c626a93 Modified copyright on all files. Also fixed a bug in the EC2 SecurityGr...
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 simp...
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 simp...
Mitch.Garnaat authored
25
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
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 simp...
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 grants ...
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 grants ...
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 grants ...
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-151...
Mitch.Garnaat authored
57 def __init__(self, status, reason, body=None):
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
58 self.status = status
59 self.reason = reason
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
60 self.body = body or ''
61 self.request_id = None
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
62 self.error_code = None
63 self.error_message = None
64 self.box_usage = None
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
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 simp...
Mitch.Garnaat authored
78
79 def __repr__(self):
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
80 return '%s: %s %s\n%s' % (self.__class__.__name__,
81 self.status, self.reason, self.body)
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
82
83 def __str__(self):
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
84 return '%s: %s %s\n%s' % (self.__class__.__name__,
85 self.status, self.reason, self.body)
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
86
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
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
11dfdd0 Added some additional attributes to BotoServerError. fixes issue 218.
Mitch.Garnaat authored
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
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
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
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
124 class S3CreateError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
125 """
126 Error creating a bucket or key on S3.
127 """
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
128 pass
129
c59fe9d Initial implementation of the new COPY method, currently available via t...
Mitch.Garnaat authored
130 class S3CopyError(BotoServerError):
131 """
132 Error copying a key on S3.
133 """
134 pass
135
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
136 class SQSError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
137 """
138 General Error on Simple Queue Service.
139 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
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
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
167 class S3ResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
168 """
169 Error in response from S3.
170 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
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)
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
194
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
195 class EC2ResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
196 """
197 Error in response from EC2.
198 """
f77a063 Incorporating a patch to parse the XML error responses. Fixes Issue-151...
Mitch.Garnaat authored
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
5d5aa35 Initial version of code. Still not complete for correct but passes simp...
Mitch.Garnaat authored
247
ef8cef7 Snapshot of SDB code that works with API version released with public be...
Mitch.Garnaat authored
248 class SDBResponseError(BotoServerError):
0496c1f General docs on the boto exceptions.
jgeewax authored
249 """
250 Error in respones from SDB.
251 """
ef8cef7 Snapshot of SDB code that works with API version released with public be...
Mitch.Garnaat authored
252 pass
253
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
254 class AWSConnectionError(BotoClientError):
0496c1f General docs on the boto exceptions.
jgeewax authored
255 """
256 General error connecting to Amazon Web Services.
257 """
49e9612 Added explicit mimetype override for uploaded files, Fixes Issue-25. Al...
Mitch.Garnaat authored
258 pass
86f1373 Merged in changes from David Strip to support proxy servers for non-SSL ...
Mitch.Garnaat authored
259
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
260 class S3DataError(BotoClientError):
0496c1f General docs on the boto exceptions.
jgeewax authored
261 """
262 Error receiving data from S3.
263 """
238451a Trying to make more sense of the exceptions.
Mitch.Garnaat authored
264 pass
86f1373 Merged in changes from David Strip to support proxy servers for non-SSL ...
Mitch.Garnaat authored
265
ed1afa4 Added some FPS support
kopertop authored
266 class FPSResponseError(BotoServerError):
267 pass
Something went wrong with that request. Please try again.