You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/09/24 11:17:14 UTC

svn commit: r1175132 - in /libcloud/trunk: libcloud/common/base.py libcloud/common/linode.py libcloud/compute/drivers/rimuhosting.py libcloud/compute/drivers/voxel.py test/compute/test_base.py test/compute/test_openstack.py

Author: tomaz
Date: Sat Sep 24 09:17:13 2011
New Revision: 1175132

URL: http://svn.apache.org/viewvc?rev=1175132&view=rev
Log:
Pass connection object to the connectionCls and rawConnectionCls constructor
instead of assigning it afterwards. Also update all the affected code and tests.

Modified:
    libcloud/trunk/libcloud/common/base.py
    libcloud/trunk/libcloud/common/linode.py
    libcloud/trunk/libcloud/compute/drivers/rimuhosting.py
    libcloud/trunk/libcloud/compute/drivers/voxel.py
    libcloud/trunk/test/compute/test_base.py
    libcloud/trunk/test/compute/test_openstack.py

Modified: libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Sat Sep 24 09:17:13 2011
@@ -40,11 +40,12 @@ class Response(object):
     error = None
     connection = None
 
-    def __init__(self, response):
+    def __init__(self, response, connection):
         self.body = response.read()
         self.status = response.status
         self.headers = dict(response.getheaders())
         self.error = response.reason
+        self.connection = connection
 
         if not self.success():
             raise Exception(self.parse_error())
@@ -84,12 +85,14 @@ class Response(object):
 
 class RawResponse(Response):
 
-    def __init__(self, response=None):
+    def __init__(self, connection):
         self._status = None
         self._response = None
         self._headers = {}
         self._error = None
         self._reason = None
+        self.connection = connection
+
 
     @property
     def response(self):
@@ -424,11 +427,11 @@ class Connection(object):
             raise ssl.SSLError(str(e))
 
         if raw:
-            response = self.rawResponseCls()
+            response = self.rawResponseCls(connection=self)
         else:
-            response = self.responseCls(self.connection.getresponse())
+            response = self.responseCls(response=self.connection.getresponse(),
+                                        connection=self)
 
-        response.connection = self
         return response
 
     def morph_action_hook(self, action):

Modified: libcloud/trunk/libcloud/common/linode.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/linode.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/linode.py (original)
+++ libcloud/trunk/libcloud/common/linode.py Sat Sep 24 09:17:13 2011
@@ -79,7 +79,7 @@ class LinodeResponse(Response):
 
     libcloud does not take advantage of batching, so a response will always
     reflect the above format.  A few weird quirks are caught here as well."""
-    def __init__(self, response):
+    def __init__(self, response, connection):
         """Instantiate a LinodeResponse from the HTTP response
 
         @keyword response: The raw response returned by urllib
@@ -88,6 +88,7 @@ class LinodeResponse(Response):
         self.status = response.status
         self.headers = dict(response.getheaders())
         self.error = response.reason
+        self.connection = connection
         self.invalid = LinodeException(0xFF,
                                        "Invalid JSON received from server")
 

Modified: libcloud/trunk/libcloud/compute/drivers/rimuhosting.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/rimuhosting.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/rimuhosting.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/rimuhosting.py Sat Sep 24 09:17:13 2011
@@ -41,11 +41,12 @@ class RimuHostingException(Exception):
         return "<RimuHostingException '%s'>" % (self.args[0])
 
 class RimuHostingResponse(Response):
-    def __init__(self, response):
+    def __init__(self, response, connection):
         self.body = response.read()
         self.status = response.status
         self.headers = dict(response.getheaders())
         self.error = response.reason
+        self.connection = connection
 
         if self.success():
             self.object = self.parse_body()

Modified: libcloud/trunk/libcloud/compute/drivers/voxel.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/voxel.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/voxel.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/voxel.py Sat Sep 24 09:17:13 2011
@@ -32,9 +32,10 @@ VOXEL_API_HOST = "api.voxel.net"
 
 class VoxelResponse(Response):
 
-    def __init__(self, response):
+    def __init__(self, response, connection):
         self.parsed = None
-        super(VoxelResponse, self).__init__(response)
+        super(VoxelResponse, self).__init__(response=response,
+                                            connection=connection)
 
     def parse_body(self):
         if not self.body:

Modified: libcloud/trunk/test/compute/test_base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_base.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_base.py (original)
+++ libcloud/trunk/test/compute/test_base.py Sat Sep 24 09:17:13 2011
@@ -38,7 +38,7 @@ class BaseTests(unittest.TestCase):
         NodeImage(id=0, name=0, driver=FakeDriver())
 
     def test_base_response(self):
-        Response(MockResponse(status=200, body='foo'))
+        Response(MockResponse(status=200, body='foo'), ConnectionKey('foo'))
 
     def test_base_node_driver(self):
         NodeDriver('foo')

Modified: libcloud/trunk/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_openstack.py?rev=1175132&r1=1175131&r2=1175132&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_openstack.py (original)
+++ libcloud/trunk/test/compute/test_openstack.py Sat Sep 24 09:17:13 2011
@@ -33,7 +33,7 @@ class OpenStackResponseTestCase(unittest
 
     def test_simple_xml_content_type_handling(self):
         http_response = MockResponse(200, OpenStackResponseTestCase.XML, headers={'content-type': 'application/xml'})
-        body = OpenStack_1_0_Response(http_response).parse_body()
+        body = OpenStack_1_0_Response(http_response, None).parse_body()
 
         self.assertTrue(hasattr(body, 'tag'), "Body should be parsed as XML")
 
@@ -41,7 +41,7 @@ class OpenStackResponseTestCase(unittest
         http_response = MockResponse(200,
                                      OpenStackResponseTestCase.XML,
                                      headers={'content-type': 'application/xml; charset=UTF-8'})
-        body = OpenStack_1_0_Response(http_response).parse_body()
+        body = OpenStack_1_0_Response(http_response, None).parse_body()
 
         self.assertTrue(hasattr(body, 'tag'), "Body should be parsed as XML")
 
@@ -49,7 +49,7 @@ class OpenStackResponseTestCase(unittest
         RESPONSE_BODY = "Accepted"
 
         http_response = MockResponse(202, RESPONSE_BODY, headers={'content-type': 'text/html'})
-        body = OpenStack_1_0_Response(http_response).parse_body()
+        body = OpenStack_1_0_Response(http_response, None).parse_body()
 
         self.assertEqual(body, RESPONSE_BODY, "Non-XML body should be returned as is")