Fix a bug in debug mode logging.

Previously, an exception would be thrown if the text contained a non-ascii
value.


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

Branch: refs/heads/trunk
Commit: 4c1f26f3440526ed531c6ecb0d70be54ca5c6b7c
Parents: 9458cba
Author: Tomaz Muraus <[email protected]>
Authored: Tue Apr 7 18:12:25 2015 +0200
Committer: Tomaz Muraus <[email protected]>
Committed: Tue Apr 7 18:15:42 2015 +0200

----------------------------------------------------------------------
 CHANGES.rst             | 10 +++++++---
 libcloud/__init__.py    |  3 ++-
 libcloud/common/base.py |  2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c1f26f3/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 0d91e82..ba5da15 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,10 +18,14 @@ General
   (GITHUB-444)
   [Gertjan Oude Lohuis]
 
+- Fix a bug in the debug mode logging (LIBCLOUD_DEBUG). Logging to the debug
+  file would throw an exception if the text contained non-ascii characters.
+  [Tomaz Muraus]
+
 Compute
 ~~~~~~~
 
-- OpenStackNodeSize objects now support optional, additional fields that are 
+- OpenStackNodeSize objects now support optional, additional fields that are
   supported in OpenStack 2.1: `ephemeral_disk`, `swap`, `extra`.
   (GITHUB-488, LIBCLOUD-682)
   [Greg Hill]
@@ -43,8 +47,8 @@ Compute
   (GITHUB-479)
   [Allard Hoeve]
 
-- OpenStack driver: deprecated ex_create_snapshot and ex_delete_snapshot in 
-  favor of create_volume_snapshot and destroy_volume_snapshot. Updated base 
+- OpenStack driver: deprecated ex_create_snapshot and ex_delete_snapshot in
+  favor of create_volume_snapshot and destroy_volume_snapshot. Updated base
   driver method create_storage_volume argument name to be optional.
   (GITHUB-478)
   [Allard Hoeve]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c1f26f3/libcloud/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/__init__.py b/libcloud/__init__.py
index f30729b..0e8c950 100644
--- a/libcloud/__init__.py
+++ b/libcloud/__init__.py
@@ -23,6 +23,7 @@ __all__ = ['__version__', 'enable_debug']
 __version__ = '0.17.1-dev'
 
 import os
+import codecs
 
 try:
     import paramiko
@@ -56,7 +57,7 @@ def _init_once():
     """
     path = os.getenv('LIBCLOUD_DEBUG')
     if path:
-        fo = open(path, 'a')
+        fo = codecs.open(path, 'a', encoding='utf8')
         enable_debug(fo)
 
         if have_paramiko:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c1f26f3/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 15a3539..fa2f82a 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -298,7 +298,7 @@ class LoggingConnection():
                 else:
                     cls = StringIO
 
-                return cls(b(self.s))
+                return cls(self.s)
         rr = r
         headers = lowercase_keys(dict(r.getheaders()))
 

Reply via email to