From 4a8efa546541b78660aa67000a871c0dc2eb2c2e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 24 Jan 2013 17:26:40 -0500 Subject: [PATCH] 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. --- mutt_ldap.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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') -- 2.26.2