From: W. Trevor King Date: Thu, 24 Jan 2013 22:26:40 +0000 (-0500) Subject: mutt_ldap.py: Also wrap stderr in a codecs writer X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4a8efa546541b78660aa67000a871c0dc2eb2c2e;p=mutt-ldap.git mutt_ldap.py: Also wrap stderr in a codecs writer So Unicode log messages handled by StreamHandler will be properly encoded. In Python 2.7.3 (and probably other 2.x versions), StreamHandler.emit() falls back on UTF-8 if stream.encoding is None. With this change, it will use the configured output encoding instead of guessing. --- diff --git a/mutt_ldap.py b/mutt_ldap.py index cab0222..efab29b 100755 --- a/mutt_ldap.py +++ b/mutt_ldap.py @@ -276,9 +276,10 @@ if __name__ == '__main__': 'system', key, CONFIG.get('system', key, raw=True) or default_encoding) - # HACK: convert sys.stdout to Unicode (not needed in Python 3) + # HACK: convert sys.std{out,err} to Unicode (not needed in Python 3) output_encoding = CONFIG.get('system', 'output-encoding') _sys.stdout = _codecs.getwriter(output_encoding)(_sys.stdout) + _sys.stderr = _codecs.getwriter(output_encoding)(_sys.stderr) # HACK: convert sys.argv to Unicode (not needed in Python 3) argv_encoding = CONFIG.get('system', 'argv-encoding')