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
e9a6cd1f
Commit
e9a6cd1f
authored
Feb 11, 2005
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix decoding in _stringify to not depend on the default encoding
(closes SF bug #1115989)
parent
7d4f98bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
Lib/test/test_xmlrpc.py
Lib/test/test_xmlrpc.py
+42
-0
Lib/xmlrpclib.py
Lib/xmlrpclib.py
+1
-1
No files found.
Lib/test/test_xmlrpc.py
View file @
e9a6cd1f
...
...
@@ -4,6 +4,13 @@ import unittest
import
xmlrpclib
from
test
import
test_support
try
:
unicode
except
NameError
:
have_unicode
=
False
else
:
have_unicode
=
True
alist
=
[{
'astring'
:
'foo@bar.baz.spam'
,
'afloat'
:
7283.43
,
'anint'
:
2
**
20
,
...
...
@@ -56,6 +63,41 @@ class XMLRPCTestCase(unittest.TestCase):
xmlrpclib
.
loads
(
strg
)[
0
][
0
])
self
.
assertRaises
(
TypeError
,
xmlrpclib
.
dumps
,
(
arg1
,))
def
test_default_encoding_issues
(
self
):
# SF bug #1115989: wrong decoding in '_stringify'
utf8
=
"""<?xml version='1.0' encoding='iso-8859-1'?>
<params>
<param><value>
<string>abc
\
x95
</string>
</value></param>
<param><value>
<struct>
<member>
<name>def
\
x96
</name>
<value><string>ghi
\
x97
</string></value>
</member>
</struct>
</value></param>
</params>
"""
old_encoding
=
sys
.
getdefaultencoding
()
reload
(
sys
)
# ugh!
sys
.
setdefaultencoding
(
"iso-8859-1"
)
try
:
(
s
,
d
),
m
=
xmlrpclib
.
loads
(
utf8
)
finally
:
sys
.
setdefaultencoding
(
old_encoding
)
items
=
d
.
items
()
if
have_unicode
:
self
.
assertEquals
(
s
,
u"abc
\
x95
"
)
self
.
assert_
(
isinstance
(
s
,
unicode
))
self
.
assertEquals
(
items
,
[(
u"def
\
x96
"
,
u"ghi
\
x97
"
)])
self
.
assert_
(
isinstance
(
items
[
0
][
0
],
unicode
))
self
.
assert_
(
isinstance
(
items
[
0
][
1
],
unicode
))
else
:
self
.
assertEquals
(
s
,
"abc
\
xc2
\
x95
"
)
self
.
assertEquals
(
items
,
[(
"def
\
xc2
\
x96
"
,
"ghi
\
xc2
\
x97
"
)])
def
test_main
():
test_support
.
run_unittest
(
XMLRPCTestCase
)
...
...
Lib/xmlrpclib.py
View file @
e9a6cd1f
...
...
@@ -173,7 +173,7 @@ if unicode:
def
_stringify
(
string
):
# convert to 7-bit ascii if possible
try
:
return
str
(
string
)
return
str
ing
.
encode
(
"ascii"
)
except
UnicodeError
:
return
string
else
:
...
...
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