From: Vinay Sajip Date: Thu, 16 Apr 2009 19:11:35 +0000 (+0000) Subject: Issue #5768: Change to Unicode output logic and test case for same. X-Git-Tag: v2.6.3rc1~417 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbe744ae436405745e19cbdbc8bac911f5c861d9;p=python Issue #5768: Change to Unicode output logic and test case for same. --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 8c2a38c496..6ce8364c21 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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() diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index fc69d4f358..7861106cb4 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -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)