Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a5cd255a
Commit
a5cd255a
authored
Oct 15, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #19267: Fix support of multibyte encoding (ex: UTF-16) in the logging
module.
parent
8ad0eac7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
Lib/logging/__init__.py
Lib/logging/__init__.py
+1
-1
Lib/test/test_logging.py
Lib/test/test_logging.py
+18
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/logging/__init__.py
View file @
a5cd255a
...
...
@@ -857,7 +857,7 @@ class StreamHandler(Handler):
try
:
if
(
isinstance
(
msg
,
unicode
)
and
getattr
(
stream
,
'encoding'
,
None
)):
ufs
=
fs
.
decode
(
stream
.
encoding
)
ufs
=
u'%s
\
n
'
try
:
stream
.
write
(
ufs
%
msg
)
except
UnicodeEncodeError
:
...
...
Lib/test/test_logging.py
View file @
a5cd255a
...
...
@@ -1060,6 +1060,24 @@ class EncodingTest(BaseTest):
#Compare against what the data should be when encoded in CP-1251
self.assertEqual(s, '
\
xe4
\
xee
\
xf1
\
xe2
\
xe8
\
xe4
\
xe0
\
xed
\
xe8
\
xff
\
n
')
def test_encoding_utf16_unicode(self):
# Issue #19267
log = logging.getLogger("
test
")
message = u'b
\
u0142
\
u0105
d'
writer_class = codecs.getwriter('utf-16-le')
writer_class.encoding = 'utf-16-le'
stream = cStringIO.StringIO()
writer = writer_class(stream, 'strict')
handler = logging.StreamHandler(writer)
log.addHandler(handler)
try:
log.warning(message)
finally:
log.removeHandler(handler)
handler.close()
s = stream.getvalue()
self.assertEqual(s, 'b
\
x00
B
\
x01
\
x05
\
x01
d
\
x00
\
n
\
x00
')
class WarningsTest(BaseTest):
...
...
Misc/NEWS
View file @
a5cd255a
...
...
@@ -370,6 +370,9 @@ Library
- Issue #17926: Fix dbm.__contains__ on 64-bit big-endian machines.
- Issue #19267: Fix support of multibyte encoding (ex: UTF-16) in the logging
module.
- Issue #17918: When using SSLSocket.accept(), if the SSL handshake failed
on the new socket, the socket would linger indefinitely. Thanks to
Peter Saveliev for reporting.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment