libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1103542 - in /incubator/libcloud/trunk/libcloud: common/base.py storage/drivers/cloudfiles.py storage/drivers/s3.py
Date Sun, 15 May 2011 21:02:19 GMT
Author: tomaz
Date: Sun May 15 21:02:18 2011
New Revision: 1103542

URL: http://svn.apache.org/viewvc?rev=1103542&view=rev
Log:
Properly capture errors if they happen in the RawResponse part.

Modified:
    incubator/libcloud/trunk/libcloud/common/base.py
    incubator/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
    incubator/libcloud/trunk/libcloud/storage/drivers/s3.py

Modified: incubator/libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/common/base.py?rev=1103542&r1=1103541&r2=1103542&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/common/base.py (original)
+++ incubator/libcloud/trunk/libcloud/common/base.py Sun May 15 21:02:18 2011
@@ -25,39 +25,6 @@ import libcloud
 from libcloud.httplib_ssl import LibcloudHTTPSConnection
 from httplib import HTTPConnection as LibcloudHTTPConnection
 
-class RawResponse(object):
-
-    def __init__(self, response=None):
-        self._status = None
-        self._response = None
-        self._headers = {}
-        self._error = None
-        self._reason = None
-
-    @property
-    def response(self):
-        if not self._response:
-            self._response = self.connection.connection.getresponse()
-        return self._response
-
-    @property
-    def status(self):
-        if not self._status:
-            self._status = self.response.status
-        return self._status
-
-    @property
-    def headers(self):
-        if not self._headers:
-            self._headers = dict(self.response.getheaders())
-        return self._headers
-
-    @property
-    def reason(self):
-        if not self._reason:
-            self._reason = self.response.reason
-        return self._reason
-
 class Response(object):
     """
     A Base Response class to derive from.
@@ -113,6 +80,43 @@ class Response(object):
         """
         return self.status == httplib.OK or self.status == httplib.CREATED
 
+class RawResponse(Response):
+
+    def __init__(self, response=None):
+        self._status = None
+        self._response = None
+        self._headers = {}
+        self._error = None
+        self._reason = None
+
+    @property
+    def response(self):
+        if not self._response:
+            response = self.connection.connection.getresponse()
+            self._response, self.body = response, response
+            if not self.success():
+                self.parse_error()
+        return self._response
+
+    @property
+    def status(self):
+        if not self._status:
+            self._status = self.response.status
+        return self._status
+
+    @property
+    def headers(self):
+        if not self._headers:
+            self._headers = dict(self.response.getheaders())
+        return self._headers
+
+    @property
+    def reason(self):
+        if not self._reason:
+            self._reason = self.response.reason
+        return self._reason
+
+
 #TODO: Move this to a better location/package
 class LoggingConnection():
     """

Modified: incubator/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py?rev=1103542&r1=1103541&r2=1103542&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py (original)
+++ incubator/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py Sun May 15 21:02:18 2011
@@ -23,7 +23,7 @@ except:
 
 from libcloud.utils import read_in_chunks
 from libcloud.common.types import MalformedResponseError, LibcloudError
-from libcloud.common.base import Response
+from libcloud.common.base import Response, RawResponse
 
 from libcloud.storage.providers import Provider
 from libcloud.storage.base import Object, Container, StorageDriver
@@ -78,6 +78,8 @@ class CloudFilesResponse(Response):
 
         return data
 
+class CloudFilesRawResponse(CloudFilesResponse, RawResponse):
+    pass
 
 class CloudFilesConnection(RackspaceBaseConnection):
     """
@@ -85,6 +87,7 @@ class CloudFilesConnection(RackspaceBase
     """
 
     responseCls = CloudFilesResponse
+    rawResponseCls = CloudFilesRawResponse
     auth_host = None
     _url_key = "storage_url"
 

Modified: incubator/libcloud/trunk/libcloud/storage/drivers/s3.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/storage/drivers/s3.py?rev=1103542&r1=1103541&r2=1103542&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/storage/drivers/s3.py (original)
+++ incubator/libcloud/trunk/libcloud/storage/drivers/s3.py Sun May 15 21:02:18 2011
@@ -26,7 +26,7 @@ from xml.etree.ElementTree import Elemen
 from libcloud.utils import fixxpath, findtext, in_development_warning
 from libcloud.utils import read_in_chunks
 from libcloud.common.types import InvalidCredsError, LibcloudError
-from libcloud.common.base import ConnectionUserAndKey
+from libcloud.common.base import ConnectionUserAndKey, RawResponse
 from libcloud.common.aws import AWSBaseResponse
 
 from libcloud.storage.base import Object, Container, StorageDriver
@@ -70,6 +70,9 @@ class S3Response(AWSBaseResponse):
         raise LibcloudError('Unknown error. Status code: %d' % (self.status),
                             driver=S3StorageDriver)
 
+class S3RawResponse(S3Response, RawResponse):
+    pass
+
 class S3Connection(ConnectionUserAndKey):
     """
     Repersents a single connection to the EC2 Endpoint
@@ -77,6 +80,7 @@ class S3Connection(ConnectionUserAndKey)
 
     host = 's3.amazonaws.com'
     responseCls = S3Response
+    rawResponseCls = S3RawResponse
 
     def add_default_params(self, params):
         expires = str(int(time.time()) + EXPIRATION_SECONDS)



Mime
View raw message