libcloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r908738 - /incubator/libcloud/trunk/libcloud/drivers/voxel.py
Date Wed, 10 Feb 2010 23:12:09 GMT
Author: pquerna
Date: Wed Feb 10 23:12:06 2010
New Revision: 908738

URL: http://svn.apache.org/viewvc?rev=908738&view=rev
Log:
start improving VoxelResponse to handle error conditions better

Modified:
    incubator/libcloud/trunk/libcloud/drivers/voxel.py

Modified: incubator/libcloud/trunk/libcloud/drivers/voxel.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/voxel.py?rev=908738&r1=908737&r2=908738&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/voxel.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/voxel.py Wed Feb 10 23:12:06 2010
@@ -28,21 +28,34 @@
 
 class VoxelResponse(Response):
 
-   def parse_body(self):
-       if not self.body:
-           return None
-       return ET.XML(self.body)
-
-   def parse_error(self):
-       try:
-           err_list = []
-           for err in ET.XML(self.body).findall('err'):
-               code = err.attrib["code"]
-               message = err.attrib["msg"]
-               err_list.append("%s: %s" % (code.text, message.text))
-           return "\n".join(err_list)
-       except ExpatError:
-           return self.body
+    def __init__(self, response):
+      self.parsed = None
+      super(VoxelResponse, self).__init__(response)
+
+    def parse_body(self):
+        if not self.body:
+            return None
+        if not self.parsed:
+            self.parsed = ET.XML(self.body)
+        return self.parsed
+
+    def parse_error(self):
+        err_list = []
+        if not self.body:
+            return None
+        if not self.parsed:
+            self.parsed = ET.XML(self.body)
+        for err in self.parsed.findall('err'):
+            err_list.append("(%s) %s" % (err.get('code'), err.get('msg')))
+        return "\n".join(err_list)
+
+    def success(self):
+        if not self.parsed:
+            self.parsed = ET.XML(self.body)
+        stat = self.parsed.get('stat')
+        if stat != "ok":
+            return False
+        return True
 
 class VoxelConnection(ConnectionUserAndKey):
 



Mime
View raw message