libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1340890 - in /libcloud/trunk: CHANGES libcloud/common/base.py
Date Mon, 21 May 2012 04:07:21 GMT
Author: tomaz
Date: Mon May 21 04:07:21 2012
New Revision: 1340890

URL: http://svn.apache.org/viewvc?rev=1340890&view=rev
Log:
Add timeout attribute to base 'Connection' class and pass it to the
connection class constructor if Python version is not 2.5. This patch has been
contributed bt Chris Gilmer and is part of LIBCLOUD-199.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/common/base.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1340890&r1=1340889&r2=1340890&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Mon May 21 04:07:21 2012
@@ -1,6 +1,12 @@
                                    -*- coding: utf-8 -*-
 
-Changes with Apache Libcloud in development:
+Changes with Apache Libcloud 0.10.1:
+
+  *) General:
+
+    - Add timeout attribute to base 'Connection' class and pass it to the
+      connection class constructor if Python version is not 2.5.
+      [Chris Gilmer]
 
   *) Compute:
     - Update IBM SBC driver so it works with IBM Smart Cloud Enterprise.

Modified: libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1340890&r1=1340889&r2=1340890&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Mon May 21 04:07:21 2012
@@ -27,7 +27,7 @@ except:
 
 import libcloud
 
-from libcloud.utils.py3 import PY3
+from libcloud.utils.py3 import PY3, PY25
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import urlencode
@@ -249,6 +249,7 @@ class LoggingConnection():
 
                 return cls(b(self.s))
         rr = r
+        original_data = body
         headers = lowercase_keys(dict(r.getheaders()))
 
         encoding = headers.get('content-encoding', None)
@@ -357,11 +358,13 @@ class Connection(object):
     connection = None
     host = '127.0.0.1'
     port = 443
+    timeout = None
     secure = 1
     driver = None
     action = None
 
-    def __init__(self, secure=True, host=None, port=None, url=None):
+    def __init__(self, secure=True, host=None, port=None, url=None,
+                 timeout=None):
         self.secure = secure and 1 or 0
         self.ua = []
         self.context = {}
@@ -383,6 +386,9 @@ class Connection(object):
             (self.host, self.port, self.secure,
              self.request_path) = self._tuple_from_url(url)
 
+        if timeout:
+            self.timeout = timeout
+
     def set_context(self, context):
         self.context = context
 
@@ -440,6 +446,11 @@ class Connection(object):
 
         kwargs = {'host': host, 'port': int(port)}
 
+        # Timeout is only supported in Python 2.6 and later
+        # http://docs.python.org/library/httplib.html#httplib.HTTPConnection
+        if self.timeout and not PY25:
+            kwargs.update({'timeout': self.timeout})
+
         connection = self.conn_classes[secure](**kwargs)
         # You can uncoment this line, if you setup a reverse proxy server
         # which proxies to your endpoint, and lets you easily capture
@@ -735,13 +746,14 @@ class ConnectionKey(Connection):
     """
     A Base Connection class to derive from, which includes a
     """
-    def __init__(self, key, secure=True, host=None, port=None, url=None):
+    def __init__(self, key, secure=True, host=None, port=None, url=None,
+                 timeout=None):
         """
         Initialize `user_id` and `key`; set `secure` to an C{int} based on
         passed value.
         """
         super(ConnectionKey, self).__init__(secure=secure, host=host,
-                                            port=port, url=url)
+                                            port=port, url=url, timeout=timeout)
         self.key = key
 
 
@@ -753,10 +765,10 @@ class ConnectionUserAndKey(ConnectionKey
     user_id = None
 
     def __init__(self, user_id, key, secure=True,
-                 host=None, port=None, url=None):
+                 host=None, port=None, url=None, timeout=None):
         super(ConnectionUserAndKey, self).__init__(key, secure=secure,
                                                    host=host, port=port,
-                                                   url=url)
+                                                   url=url, timeout=timeout)
         self.user_id = user_id
 
 



Mime
View raw message