[New-bugs-announce] [issue6991] logging encoding failes some situation

Naoki INADA report at bugs.python.org
Fri Sep 25 07:29:27 CEST 2009


New submission from Naoki INADA <songofacandy at gmail.com>:

When stream is codecs.writer object, stream.write(string) does
string.decode() internally and it may cause UnicodeDecodeError.

Then, fallback to utf-8 is not good.
I think good fallback logic is:
* When message is unicode, message.encode(stream.encoding or 'ascii',
'backslashreplace')
* When message is bytes, message.encode('string_escape')

Attached patch contains this logic, refactoring and test.

----------
components: Library (Lib)
files: logging_encode.patch
keywords: patch
messages: 93100
nosy: naoki
severity: normal
status: open
title: logging encoding failes some situation
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file14970/logging_encode.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6991>
_______________________________________


More information about the New-bugs-announce mailing list