Commit a5cd255a authored by Victor Stinner's avatar Victor Stinner

Close #19267: Fix support of multibyte encoding (ex: UTF-16) in the logging

module.
parent 8ad0eac7
......@@ -857,7 +857,7 @@ class StreamHandler(Handler):
try:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None)):
ufs = fs.decode(stream.encoding)
ufs = u'%s\n'
try:
stream.write(ufs % msg)
except UnicodeEncodeError:
......
......@@ -1060,6 +1060,24 @@ class EncodingTest(BaseTest):
#Compare against what the data should be when encoded in CP-1251
self.assertEqual(s, '\xe4\xee \xf1\xe2\xe8\xe4\xe0\xed\xe8\xff\n')
def test_encoding_utf16_unicode(self):
# Issue #19267
log = logging.getLogger("test")
message = u'b\u0142\u0105d'
writer_class = codecs.getwriter('utf-16-le')
writer_class.encoding = 'utf-16-le'
stream = cStringIO.StringIO()
writer = writer_class(stream, 'strict')
handler = logging.StreamHandler(writer)
log.addHandler(handler)
try:
log.warning(message)
finally:
log.removeHandler(handler)
handler.close()
s = stream.getvalue()
self.assertEqual(s, 'b\x00B\x01\x05\x01d\x00\n\x00')
class WarningsTest(BaseTest):
......
......@@ -370,6 +370,9 @@ Library
- Issue #17926: Fix dbm.__contains__ on 64-bit big-endian machines.
- Issue #19267: Fix support of multibyte encoding (ex: UTF-16) in the logging
module.
- Issue #17918: When using SSLSocket.accept(), if the SSL handshake failed
on the new socket, the socket would linger indefinitely. Thanks to
Peter Saveliev for reporting.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment