mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #5768: Change to Unicode output logic and test case for same.
This commit is contained in:
parent
b729135eee
commit
cbe744ae43
2 changed files with 5 additions and 4 deletions
|
@ -764,11 +764,11 @@ class StreamHandler(Handler):
|
||||||
stream.write(fs % msg)
|
stream.write(fs % msg)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if (isinstance(msg, unicode) or
|
if (isinstance(msg, unicode) and
|
||||||
getattr(stream, 'encoding', None) is None):
|
getattr(stream, 'encoding', None)):
|
||||||
stream.write(fs % msg)
|
stream.write(fs.decode(stream.encoding) % msg)
|
||||||
else:
|
else:
|
||||||
stream.write(fs % msg.encode(stream.encoding))
|
stream.write(fs % msg)
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
stream.write(fs % msg.encode("UTF-8"))
|
stream.write(fs % msg.encode("UTF-8"))
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
|
@ -893,6 +893,7 @@ class EncodingTest(BaseTest):
|
||||||
message = u'\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
|
message = u'\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
|
||||||
#Ensure it's written in a Cyrillic encoding
|
#Ensure it's written in a Cyrillic encoding
|
||||||
writer_class = codecs.getwriter('cp1251')
|
writer_class = codecs.getwriter('cp1251')
|
||||||
|
writer_class.encoding = 'cp1251'
|
||||||
stream = cStringIO.StringIO()
|
stream = cStringIO.StringIO()
|
||||||
writer = writer_class(stream, 'strict')
|
writer = writer_class(stream, 'strict')
|
||||||
handler = logging.StreamHandler(writer)
|
handler = logging.StreamHandler(writer)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue