Skip to content

Commit

Permalink
Restore Python 3.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Oct 1, 2014
1 parent 42f9d11 commit b3f903e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion coloredlogs/__init__.py
Expand Up @@ -10,7 +10,7 @@
"""

# Semi-standard module versioning.
__version__ = '0.7'
__version__ = '0.7.1'

# Standard library modules.
import copy
Expand Down
5 changes: 3 additions & 2 deletions coloredlogs/converter.py
Expand Up @@ -48,7 +48,7 @@ def main():
else:
print(html_output)

def capture(command):
def capture(command, encoding='UTF-8'):
"""
Capture the output of an external program as if it runs in an interactive terminal.
Expand All @@ -57,14 +57,15 @@ def capture(command):
running in an interactive terminal (including ANSI escape sequences).
:param command: The program name and its arguments (a list of strings).
:param encoding: The encoding to use to decode the output (a string).
:returns: The output of the command.
"""
script_command = ['script', '-qe']
script_command.extend(['-c', ' '.join(pipes.quote(a) for a in command)])
script_command.append('/dev/null')
script_process = subprocess.Popen(script_command, stdout=subprocess.PIPE)
stdout, stderr = script_process.communicate()
return stdout
return stdout.decode(encoding)

def convert(text):
"""
Expand Down
11 changes: 9 additions & 2 deletions coloredlogs/tests.py
Expand Up @@ -9,9 +9,16 @@
import random
import re
import string
import StringIO
import unittest

# StringIO.StringIO() vs io.StringIO().
try:
# Python 2.x.
from StringIO import StringIO
except ImportError:
# Python 3.x.
from io import StringIO

# The module we're testing.
import coloredlogs
import coloredlogs.converter
Expand Down Expand Up @@ -39,7 +46,7 @@ def setUp(self):
coloredlogs.install()
coloredlogs.set_level(logging.INFO)
# Reset local state.
self.stream = StringIO.StringIO()
self.stream = StringIO()
self.handler = coloredlogs.ColoredStreamHandler(stream=self.stream, isatty=False)
self.logger_name = ''.join(random.choice(string.ascii_letters) for i in range(25))
self.logger = verboselogs.VerboseLogger(self.logger_name)
Expand Down

0 comments on commit b3f903e

Please sign in to comment.