Issue #7470: logging: fix bug in Unicode encoding fallback.

This commit is contained in:
Vinay Sajip 2009-12-11 09:16:01 +00:00
parent 6c4847fbee
commit 5cc4e2a040
2 changed files with 5 additions and 3 deletions

View File

@ -821,9 +821,9 @@ class StreamHandler(Handler):
try:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None)):
fs = fs.decode(stream.encoding)
ufs = fs.decode(stream.encoding)
try:
stream.write(fs % msg)
stream.write(ufs % msg)
except UnicodeEncodeError:
#Printing to terminals sometimes fails. For example,
#with an encoding of 'cp1251', the above write will
@ -831,7 +831,7 @@ class StreamHandler(Handler):
#the codecs module, but fail when writing to a
#terminal even when the codepage is set to cp1251.
#An extra encoding step seems to be needed.
stream.write((fs % msg).encode(stream.encoding))
stream.write((ufs % msg).encode(stream.encoding))
else:
stream.write(fs % msg)
except UnicodeError:

View File

@ -15,6 +15,8 @@ Core and Builtins
Library
-------
- Issue #7470: logging: fix bug in Unicode encoding fallback.
- Issue #5949: fixed IMAP4_SSL hang when the IMAP server response is
missing proper end-of-line termination.