Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: third_party/boto/boto/exception.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/boto/boto/endpoints.json ('k') | third_party/boto/boto/fps/response.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/boto/boto/exception.py
===================================================================
--- third_party/boto/boto/exception.py (revision 33376)
+++ third_party/boto/boto/exception.py (working copy)
@@ -27,6 +27,7 @@
import base64
import xml.sax
from boto import handler
+from boto.compat import json
from boto.resultset import ResultSet
@@ -84,17 +85,45 @@
# Attempt to parse the error response. If body isn't present,
# then just ignore the error response.
if self.body:
- try:
- h = handler.XmlHandlerWrapper(self, self)
- h.parseString(self.body)
- except (TypeError, xml.sax.SAXParseException), pe:
- # Remove unparsable message body so we don't include garbage
- # in exception. But first, save self.body in self.error_message
- # because occasionally we get error messages from Eucalyptus
- # that are just text strings that we want to preserve.
- self.message = self.body
- self.body = None
+ # Check if it looks like a ``dict``.
+ if hasattr(self.body, 'items'):
+ # It's not a string, so trying to parse it will fail.
+ # But since it's data, we can work with that.
+ self.request_id = self.body.get('RequestId', None)
+ if 'Error' in self.body:
+ # XML-style
+ error = self.body.get('Error', {})
+ self.error_code = error.get('Code', None)
+ self.message = error.get('Message', None)
+ else:
+ # JSON-style.
+ self.message = self.body.get('message', None)
+ else:
+ try:
+ h = handler.XmlHandlerWrapper(self, self)
+ h.parseString(self.body)
+ except (TypeError, xml.sax.SAXParseException), pe:
+ # What if it's JSON? Let's try that.
+ try:
+ parsed = json.loads(self.body)
+
+ if 'RequestId' in parsed:
+ self.request_id = parsed['RequestId']
+ if 'Error' in parsed:
+ if 'Code' in parsed['Error']:
+ self.error_code = parsed['Error']['Code']
+ if 'Message' in parsed['Error']:
+ self.message = parsed['Error']['Message']
+
+ except (TypeError, ValueError):
+ # Remove unparsable message body so we don't include garbage
+ # in exception. But first, save self.body in self.error_message
+ # because occasionally we get error messages from Eucalyptus
+ # that are just text strings that we want to preserve.
+ self.message = self.body
+ self.body = None
+
def __getattr__(self, name):
if name == 'error_message':
return self.message
« no previous file with comments | « third_party/boto/boto/endpoints.json ('k') | third_party/boto/boto/fps/response.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698