Refactor sys.stdout wrapping into a function.

This commit is contained in:
Bastian Kleineidam 2011-03-11 20:05:27 +01:00
parent b845335628
commit 8da37a32ee

View file

@ -54,6 +54,14 @@ ContentTypes = dict(
other=0,
)
def get_stdout_writer (encoding=i18n.default_encoding, errors='replace'):
"""Get wrapped sys.stdout writer with given encoding and error
handling."""
Writer = codecs.getwriter(encoding)
return Writer(sys.stdout, errors)
class LogStatistics (object):
"""Gather log statistics:
- number of errors, warnings and valid links
@ -199,8 +207,8 @@ class Logger (object):
elif 'fd' in args:
self.fd = args['fd']
else:
Writer = codecs.getwriter(self.output_encoding)
self.fd = Writer(sys.stdout, self.codec_errors)
self.fd = get_stdout_writer(encoding=self.output_encoding,
errors=self.codec_errors)
def start_fileoutput (self):
"""Start output to configured file."""