Have log_printer use utf8 stream.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2015-08-24 12:43:08 -04:00
parent feaa4a5f1a
commit 7e4c3142d7
2 changed files with 7 additions and 5 deletions

View File

@ -5,7 +5,9 @@ import sys
from itertools import cycle
import six
from six import next
from compose import utils
from . import colors
from .multiplexer import Multiplexer
from .utils import split_buffer
@ -17,13 +19,11 @@ class LogPrinter(object):
self.attach_params = attach_params or {}
self.prefix_width = self._calculate_prefix_width(containers)
self.generators = self._make_log_generators(monochrome)
self.output = output
self.output = utils.get_output_stream(output)
def run(self):
mux = Multiplexer(self.generators)
for line in mux.loop():
if isinstance(line, six.text_type) and not six.PY3:
line = line.encode('utf-8')
self.output.write(line)
def _calculate_prefix_width(self, containers):

View File

@ -32,7 +32,6 @@ class LogPrinterTest(unittest.TestCase):
output = self.get_default_output()
self.assertIn('\033[', output)
@unittest.skipIf(six.PY3, "Only test unicode in python2")
def test_unicode(self):
glyph = u'\u2022'
@ -42,7 +41,10 @@ class LogPrinterTest(unittest.TestCase):
container = MockContainer(reader)
output = run_log_printer([container])
self.assertIn(glyph, output.decode('utf-8'))
if six.PY2:
output = output.decode('utf-8')
self.assertIn(glyph, output)
def run_log_printer(containers, monochrome=False):