Output fixes.

This commit is contained in:
Bastian Kleineidam 2013-04-30 20:26:36 +02:00
parent b4d642d408
commit 1478f22099

View file

@ -14,19 +14,21 @@ lock = threading.Lock()
class Output(object): class Output(object):
"""Print output with context, indentation and optional timestamps.""" """Print output with context, indentation and optional timestamps."""
def __init__(self, stream=sys.stdout, encoding=None): def __init__(self, stream=None):
"""Initialize context and indentation.""" """Initialize context and indentation."""
self.context = u'' self.context = u''
self.level = 0 self.level = 0
self.timestamps = False self.timestamps = False
if encoding is None: if stream is None:
if hasattr(stream, "encoding") and stream.encoding: if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:
self.encoding = stream.encoding self.encoding = sys.stdout.encoding
else: else:
self.encoding = 'utf-8' self.encoding = 'utf-8'
else: if sys.version_info[0] >= 3:
self.encoding = encoding stream = sys.stdout.buffer
stream = codecs.getwriter(self.encoding)(stream) else:
stream = sys.stdout
stream = codecs.getwriter(self.encoding)(stream, 'replace')
self.setStream(stream) self.setStream(stream)
def setStream(self, stream): def setStream(self, stream):