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:
#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):
- 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.