You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/04/05 13:17:01 UTC

[10/33] libcloud git commit: Consolidate the logging connection into a single class now that the connection classes are no longer a tuple

Consolidate the logging connection into a single class now that the connection classes are no longer a tuple


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d52e8eff
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d52e8eff
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d52e8eff

Branch: refs/heads/requests
Commit: d52e8eff25edbdfc5b2f67ec55aad94d67d2c15f
Parents: 6cc6e3c
Author: anthony-shaw <an...@gmail.com>
Authored: Tue Mar 29 19:29:07 2016 +1100
Committer: anthony-shaw <an...@gmail.com>
Committed: Tue Mar 29 19:29:07 2016 +1100

----------------------------------------------------------------------
 libcloud/__init__.py                | 10 ++++----
 libcloud/test/test_init.py          |  9 +++-----
 libcloud/utils/loggingconnection.py | 39 +++++---------------------------
 3 files changed, 13 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d52e8eff/libcloud/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/__init__.py b/libcloud/__init__.py
index 3ed520d..bc68d73 100644
--- a/libcloud/__init__.py
+++ b/libcloud/__init__.py
@@ -40,12 +40,10 @@ def enable_debug(fo):
     :type fo: File like object, only write operations are used.
     """
     from libcloud.common.base import (Connection,
-                                      LoggingHTTPConnection,
-                                      LoggingHTTPSConnection)
-    LoggingHTTPSConnection.log = fo
-    LoggingHTTPConnection.log = fo
-    Connection.conn_classes = (LoggingHTTPConnection,
-                               LoggingHTTPSConnection)
+                                      LoggingConnection)
+    LoggingConnection.log = fo
+    LoggingConnection.log = fo
+    Connection.conn_class = LoggingConnection
 
 
 def _init_once():

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d52e8eff/libcloud/test/test_init.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_init.py b/libcloud/test/test_init.py
index bd428ef..d7069c3 100644
--- a/libcloud/test/test_init.py
+++ b/libcloud/test/test_init.py
@@ -25,8 +25,7 @@ except ImportError:
     have_paramiko = False
 
 from libcloud import _init_once
-from libcloud.utils.loggingconnection import LoggingHTTPConnection
-from libcloud.utils.loggingconnection import LoggingHTTPSConnection
+from libcloud.utils.loggingconnection import LoggingConnection
 
 from libcloud.test import unittest
 
@@ -36,8 +35,7 @@ class TestUtils(unittest.TestCase):
         # Debug mode is disabled
         _init_once()
 
-        self.assertEqual(LoggingHTTPConnection.log, None)
-        self.assertEqual(LoggingHTTPSConnection.log, None)
+        self.assertEqual(LoggingConnection.log, None)
 
         if have_paramiko:
             logger = paramiko.util.logging.getLogger()
@@ -48,8 +46,7 @@ class TestUtils(unittest.TestCase):
         os.environ['LIBCLOUD_DEBUG'] = '/dev/null'
         _init_once()
 
-        self.assertTrue(LoggingHTTPConnection.log is not None)
-        self.assertTrue(LoggingHTTPSConnection.log is not None)
+        self.assertTrue(LoggingConnection.log is not None)
 
         if have_paramiko:
             logger = paramiko.util.logging.getLogger()

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d52e8eff/libcloud/utils/loggingconnection.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/loggingconnection.py b/libcloud/utils/loggingconnection.py
index 02a2a41..966023a 100644
--- a/libcloud/utils/loggingconnection.py
+++ b/libcloud/utils/loggingconnection.py
@@ -26,8 +26,7 @@ from xml.dom.minidom import parseString
 import sys
 import os
 
-from libcloud.common.base import (LibcloudHTTPConnection,
-                                  LibcloudHTTPSConnection,
+from libcloud.common.base import (LibcloudConnection,
                                   HTTPResponse)
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import PY3
@@ -40,7 +39,7 @@ from libcloud.utils.misc import lowercase_keys
 from libcloud.utils.compression import decompress_data
 
 
-class LoggingConnection():
+class LoggingBaseConnection():
     """
     Debug class to log all HTTP(s) requests as they could be made
     with the curl command.
@@ -170,7 +169,7 @@ class LoggingConnection():
         return " ".join(cmd)
 
 
-class LoggingHTTPSConnection(LoggingConnection, LibcloudHTTPSConnection):
+class LoggingConnection(LoggingBaseConnection, LibcloudConnection):
     """
     Utility Class for logging HTTPS connections
     """
@@ -178,7 +177,7 @@ class LoggingHTTPSConnection(LoggingConnection, LibcloudHTTPSConnection):
     protocol = 'https'
 
     def getresponse(self):
-        r = LibcloudHTTPSConnection.getresponse(self)
+        r = LibcloudConnection.getresponse(self)
         if self.log is not None:
             r, rv = self._log_response(r)
             self.log.write(rv + "\n")
@@ -192,31 +191,5 @@ class LoggingHTTPSConnection(LoggingConnection, LibcloudHTTPSConnection):
             self.log.write(pre +
                            self._log_curl(method, url, body, headers) + "\n")
             self.log.flush()
-        return LibcloudHTTPSConnection.request(self, method, url, body,
-                                               headers)
-
-
-class LoggingHTTPConnection(LoggingConnection, LibcloudHTTPConnection):
-    """
-    Utility Class for logging HTTP connections
-    """
-
-    protocol = 'http'
-
-    def getresponse(self):
-        r = LibcloudHTTPConnection.getresponse(self)
-        if self.log is not None:
-            r, rv = self._log_response(r)
-            self.log.write(rv + "\n")
-            self.log.flush()
-        return r
-
-    def request(self, method, url, body=None, headers=None):
-        headers.update({'X-LC-Request-ID': str(id(self))})
-        if self.log is not None:
-            pre = '# -------- begin %d request ----------\n' % id(self)
-            self.log.write(pre +
-                           self._log_curl(method, url, body, headers) + "\n")
-            self.log.flush()
-        return LibcloudHTTPConnection.request(self, method, url,
-                                              body, headers)
+        return LibcloudConnection.request(self, method, url, body,
+                                          headers)