summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2009-04-22 12:10:47 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2009-04-22 12:10:47 (GMT)
commitcbb530872354fb4eb3b8b5bbaa36db38a0d9a64a (patch)
tree6511973c2d967e20ce93ba727233e54e06cf6cbc /Lib/logging
parent4c074382bd2dc4857a8c9afcac7e5322dc6c77e5 (diff)
downloadcpython-cbb530872354fb4eb3b8b5bbaa36db38a0d9a64a.zip
cpython-cbb530872354fb4eb3b8b5bbaa36db38a0d9a64a.tar.gz
cpython-cbb530872354fb4eb3b8b5bbaa36db38a0d9a64a.tar.bz2
Issue #5170: Fixed regression caused when fixing #5768.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index d20b37b..0b5e671 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -766,7 +766,17 @@ class StreamHandler(Handler):
try:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None)):
- stream.write(fs.decode(stream.encoding) % msg)
+ fs = fs.decode(stream.encoding)
+ try:
+ stream.write(fs % msg)
+ except UnicodeEncodeError:
+ #Printing to terminals sometimes fails. For example,
+ #with an encoding of 'cp1251', the above write will
+ #work if written to a stream opened or wrapped by
+ #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))
else:
stream.write(fs % msg)
except UnicodeError: