Skip to content

Commit

Permalink
Fix LIBCLOUD_DEBUG mode - make sure it works correctly under Python 3.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Aug 31, 2015
1 parent 1df5767 commit d38712e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions libcloud/__init__.py
Expand Up @@ -55,12 +55,22 @@ def _init_once():
This checks for the LIBCLOUD_DEBUG environment variable, which if it exists
is where we will log debug information about the provider transports.
"""
from libcloud.utils.py3 import PY3

path = os.getenv('LIBCLOUD_DEBUG')
if path:
fo = codecs.open(path, 'a', encoding='utf8')
mode = 'a'

# Special case for /dev/stderr and /dev/stdout on Python 3.
# Opening those files in append mode will throw "illegal seek"
# exception there.
if path in ['/dev/stderr', '/dev/stdout'] and PY3:
mode = 'w'

fo = codecs.open(path, mode, encoding='utf8')
enable_debug(fo)

if have_paramiko:
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
if have_paramiko:
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)

_init_once()
4 changes: 2 additions & 2 deletions libcloud/common/base.py
Expand Up @@ -313,7 +313,7 @@ def _log_response(self, r):
ht += "\r\n"

# this is evil. laugh with me. ha arharhrhahahaha
class fakesock:
class fakesock(object):
def __init__(self, s):
self.s = s

Expand All @@ -324,7 +324,7 @@ def makefile(self, *args, **kwargs):
else:
cls = StringIO

return cls(self.s)
return cls(b(self.s))
rr = r
headers = lowercase_keys(dict(r.getheaders()))

Expand Down

0 comments on commit d38712e

Please sign in to comment.