[Python-checkins] r71657 - in python/trunk/Lib: logging/__init__.py test/test_logging.py

vinay.sajip python-checkins at python.org
Thu Apr 16 21:07:37 CEST 2009


Author: vinay.sajip
Date: Thu Apr 16 21:07:37 2009
New Revision: 71657

Log:
Issue #5768: Change to Unicode output logic and test case for same.

Modified:
   python/trunk/Lib/logging/__init__.py
   python/trunk/Lib/test/test_logging.py

Modified: python/trunk/Lib/logging/__init__.py
==============================================================================
--- python/trunk/Lib/logging/__init__.py	(original)
+++ python/trunk/Lib/logging/__init__.py	Thu Apr 16 21:07:37 2009
@@ -753,7 +753,7 @@
         The record is then written to the stream with a trailing newline.  If
         exception information is present, it is formatted using
         traceback.print_exception and appended to the stream.  If the stream
-        has an 'encoding' attribute, it is used to encode the message before
+        has an 'encoding' attribute, it is used to determine how to do the
         output to the stream.
         """
         try:
@@ -764,11 +764,11 @@
                 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()

Modified: python/trunk/Lib/test/test_logging.py
==============================================================================
--- python/trunk/Lib/test/test_logging.py	(original)
+++ python/trunk/Lib/test/test_logging.py	Thu Apr 16 21:07:37 2009
@@ -894,6 +894,7 @@
         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)


More information about the Python-checkins mailing list