]> granicus.if.org Git - python/commitdiff
Issue #5768: Change to Unicode output logic and test case for same.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 16 Apr 2009 19:11:35 +0000 (19:11 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 16 Apr 2009 19:11:35 +0000 (19:11 +0000)
Lib/logging/__init__.py
Lib/test/test_logging.py

index 8c2a38c496c95d55dfd4bf2ba3f2e7bbcf744a9a..6ce8364c21250d7e20decf4fa615189c32440758 100644 (file)
@@ -764,11 +764,11 @@ class StreamHandler(Handler):
                 stream.write(fs % msg)
             else:
                 try:
-                    if (isinstance(msg, unicode) or
-                        getattr(stream, 'encoding', None) is None):
-                        stream.write(fs % msg)
+                    if (isinstance(msg, unicode) and
+                        getattr(stream, 'encoding', None)):
+                        stream.write(fs.decode(stream.encoding) % msg)
                     else:
-                        stream.write(fs % msg.encode(stream.encoding))
+                        stream.write(fs % msg)
                 except UnicodeError:
                     stream.write(fs % msg.encode("UTF-8"))
             self.flush()
index fc69d4f35819eae355e3650a6fa3f65ca93f01c1..7861106cb492937ce50dcc3781672b04d3704a1a 100644 (file)
@@ -893,6 +893,7 @@ class EncodingTest(BaseTest):
         message = u'\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
         #Ensure it's written in a Cyrillic encoding
         writer_class = codecs.getwriter('cp1251')
+        writer_class.encoding = 'cp1251'
         stream = cStringIO.StringIO()
         writer = writer_class(stream, 'strict')
         handler = logging.StreamHandler(writer)