| OLD | NEW |
| 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. | 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 3 # All rights reserved. | 3 # All rights reserved. |
| 4 # | 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a | 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the | 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including | 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- | 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit | 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- | 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 self.error_code = None | 78 self.error_code = None |
| 79 self.error_message = None | 79 self.error_message = None |
| 80 self.box_usage = None | 80 self.box_usage = None |
| 81 | 81 |
| 82 # Attempt to parse the error response. If body isn't present, | 82 # Attempt to parse the error response. If body isn't present, |
| 83 # then just ignore the error response. | 83 # then just ignore the error response. |
| 84 if self.body: | 84 if self.body: |
| 85 try: | 85 try: |
| 86 h = handler.XmlHandler(self, self) | 86 h = handler.XmlHandler(self, self) |
| 87 xml.sax.parseString(self.body, h) | 87 xml.sax.parseString(self.body, h) |
| 88 except xml.sax.SAXParseException, pe: | 88 except (TypeError, xml.sax.SAXParseException), pe: |
| 89 # Go ahead and clean up anything that may have | 89 # Remove unparsable message body so we don't include garbage |
| 90 # managed to get into the error data so we | 90 # in exception. But first, save self.body in self.error_message |
| 91 # don't get partial garbage. | 91 # because occasionally we get error messages from Eucalyptus |
| 92 print "Warning: failed to parse error message from AWS: %s" % pe | 92 # that are just text strings that we want to preserve. |
| 93 self._cleanupParsedProperties() | 93 self.error_message = self.body |
| 94 self.body = None |
| 94 | 95 |
| 95 def __getattr__(self, name): | 96 def __getattr__(self, name): |
| 96 if name == 'message': | 97 if name == 'message': |
| 97 return self.error_message | 98 return self.error_message |
| 98 if name == 'code': | 99 if name == 'code': |
| 99 return self.error_code | 100 return self.error_code |
| 100 raise AttributeError | 101 raise AttributeError |
| 101 | 102 |
| 102 def __repr__(self): | 103 def __repr__(self): |
| 103 return '%s: %s %s\n%s' % (self.__class__.__name__, | 104 return '%s: %s %s\n%s' % (self.__class__.__name__, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 self.request_id = value | 291 self.request_id = value |
| 291 else: | 292 else: |
| 292 return None # don't call subclass here | 293 return None # don't call subclass here |
| 293 | 294 |
| 294 def _cleanupParsedProperties(self): | 295 def _cleanupParsedProperties(self): |
| 295 BotoServerError._cleanupParsedProperties(self) | 296 BotoServerError._cleanupParsedProperties(self) |
| 296 self._errorResultSet = [] | 297 self._errorResultSet = [] |
| 297 for p in ('errors'): | 298 for p in ('errors'): |
| 298 setattr(self, p, None) | 299 setattr(self, p, None) |
| 299 | 300 |
| 301 class DynamoDBResponseError(BotoServerError): |
| 302 """ |
| 303 This exception expects the fully parsed and decoded JSON response |
| 304 body to be passed as the body parameter. |
| 305 |
| 306 :ivar status: The HTTP status code. |
| 307 :ivar reason: The HTTP reason message. |
| 308 :ivar body: The Python dict that represents the decoded JSON |
| 309 response body. |
| 310 :ivar error_message: The full description of the AWS error encountered. |
| 311 :ivar error_code: A short string that identifies the AWS error |
| 312 (e.g. ConditionalCheckFailedException) |
| 313 """ |
| 314 |
| 315 def __init__(self, status, reason, body=None, *args): |
| 316 self.status = status |
| 317 self.reason = reason |
| 318 self.body = body |
| 319 if self.body: |
| 320 self.error_message = self.body.get('message', None) |
| 321 self.error_code = self.body.get('__type', None) |
| 322 if self.error_code: |
| 323 self.error_code = self.error_code.split('#')[-1] |
| 324 |
| 300 class EmrResponseError(BotoServerError): | 325 class EmrResponseError(BotoServerError): |
| 301 """ | 326 """ |
| 302 Error in response from EMR | 327 Error in response from EMR |
| 303 """ | 328 """ |
| 304 pass | 329 pass |
| 305 | 330 |
| 306 class _EC2Error: | 331 class _EC2Error: |
| 307 | 332 |
| 308 def __init__(self, connection=None): | 333 def __init__(self, connection=None): |
| 309 self.connection = connection | 334 self.connection = connection |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 Exception.__init__(self, message) | 386 Exception.__init__(self, message) |
| 362 self.message = message | 387 self.message = message |
| 363 | 388 |
| 364 class InvalidAclError(Exception): | 389 class InvalidAclError(Exception): |
| 365 """Exception raised when ACL XML is invalid.""" | 390 """Exception raised when ACL XML is invalid.""" |
| 366 | 391 |
| 367 def __init__(self, message): | 392 def __init__(self, message): |
| 368 Exception.__init__(self, message) | 393 Exception.__init__(self, message) |
| 369 self.message = message | 394 self.message = message |
| 370 | 395 |
| 396 class InvalidCorsError(Exception): |
| 397 """Exception raised when CORS XML is invalid.""" |
| 398 |
| 399 def __init__(self, message): |
| 400 Exception.__init__(self, message) |
| 401 self.message = message |
| 402 |
| 371 class NoAuthHandlerFound(Exception): | 403 class NoAuthHandlerFound(Exception): |
| 372 """Is raised when no auth handlers were found ready to authenticate.""" | 404 """Is raised when no auth handlers were found ready to authenticate.""" |
| 373 pass | 405 pass |
| 374 | 406 |
| 375 class TooManyAuthHandlerReadyToAuthenticate(Exception): | 407 class TooManyAuthHandlerReadyToAuthenticate(Exception): |
| 376 """Is raised when there are more than one auth handler ready. | 408 """Is raised when there are more than one auth handler ready. |
| 377 | 409 |
| 378 In normal situation there should only be one auth handler that is ready to | 410 In normal situation there should only be one auth handler that is ready to |
| 379 authenticate. In case where more than one auth handler is ready to | 411 authenticate. In case where more than one auth handler is ready to |
| 380 authenticate, we raise this exception, to prevent unpredictable behavior | 412 authenticate, we raise this exception, to prevent unpredictable behavior |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 """ | 463 """ |
| 432 | 464 |
| 433 def __init__(self, message, disposition): | 465 def __init__(self, message, disposition): |
| 434 Exception.__init__(self, message, disposition) | 466 Exception.__init__(self, message, disposition) |
| 435 self.message = message | 467 self.message = message |
| 436 self.disposition = disposition | 468 self.disposition = disposition |
| 437 | 469 |
| 438 def __repr__(self): | 470 def __repr__(self): |
| 439 return 'ResumableDownloadException("%s", %s)' % ( | 471 return 'ResumableDownloadException("%s", %s)' % ( |
| 440 self.message, self.disposition) | 472 self.message, self.disposition) |
| OLD | NEW |