summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-01-18 17:35:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-01-18 17:35:23 (GMT)
commit2f173fe26b48eddfb76a715db476063e95531ff6 (patch)
tree50787b1f43d06b9c5e15f4dd32cad6c888ba74f7 /Lib
parent43beaebffb55e0b9250d996fd7a10f6e575f34e0 (diff)
downloadcpython-2f173fe26b48eddfb76a715db476063e95531ff6.zip
cpython-2f173fe26b48eddfb76a715db476063e95531ff6.tar.gz
cpython-2f173fe26b48eddfb76a715db476063e95531ff6.tar.bz2
Issue #21847: Fixed xmlrpclib and tests on Unicode-disabled builds.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xmlrpc.py19
-rw-r--r--Lib/xmlrpclib.py4
2 files changed, 11 insertions, 12 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 2bb3978..727193a 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -23,13 +23,6 @@ try:
except ImportError:
gzip = None
-try:
- unicode
-except NameError:
- have_unicode = False
-else:
- have_unicode = True
-
alist = [{'astring': 'foo@bar.baz.spam',
'afloat': 7283.43,
'anint': 2**20,
@@ -37,8 +30,6 @@ alist = [{'astring': 'foo@bar.baz.spam',
'anotherlist': ['.zyx.41'],
'abase64': xmlrpclib.Binary("my dog has fleas"),
'boolean': xmlrpclib.False,
- 'unicode': u'\u4000\u6000\u8000',
- u'ukey\u4000': 'regular value',
'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
'datetime2': xmlrpclib.DateTime(
(2005, 02, 10, 11, 41, 23, 0, 1, -1)),
@@ -46,6 +37,12 @@ alist = [{'astring': 'foo@bar.baz.spam',
datetime.datetime(2005, 02, 10, 11, 41, 23)),
}]
+if test_support.have_unicode:
+ alist[0].update({
+ 'unicode': test_support.u(r'\u4000\u6000\u8000'),
+ test_support.u(r'ukey\u4000'): 'regular value',
+ })
+
class XMLRPCTestCase(unittest.TestCase):
def test_dump_load(self):
@@ -150,6 +147,7 @@ class XMLRPCTestCase(unittest.TestCase):
xmlrpclib.loads(strg)[0][0])
self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
+ @test_support.requires_unicode
def test_default_encoding_issues(self):
# SF bug #1115989: wrong decoding in '_stringify'
utf8 = """<?xml version='1.0' encoding='iso-8859-1'?>
@@ -182,7 +180,7 @@ class XMLRPCTestCase(unittest.TestCase):
temp_sys.setdefaultencoding(old_encoding)
items = d.items()
- if have_unicode:
+ if test_support.have_unicode:
self.assertEqual(s, u"abc \x95")
self.assertIsInstance(s, unicode)
self.assertEqual(items, [(u"def \x96", u"ghi \x97")])
@@ -477,6 +475,7 @@ class SimpleServerTestCase(BaseServerTestCase):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+ @test_support.requires_unicode
def test_unicode_host(self):
server = xmlrpclib.ServerProxy(u"http://%s:%d/RPC2"%(ADDR, PORT))
self.assertEqual(server.add("a", u"\xe9"), u"a\xe9")
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index db185a6..a1800a1 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -393,7 +393,7 @@ class DateTime:
elif datetime and isinstance(other, datetime.datetime):
s = self.value
o = other.strftime("%Y%m%dT%H:%M:%S")
- elif isinstance(other, (str, unicode)):
+ elif isinstance(other, basestring):
s = self.value
o = other
elif hasattr(other, "timetuple"):
@@ -1560,7 +1560,7 @@ class ServerProxy:
allow_none=0, use_datetime=0, context=None):
# establish a "logical" server connection
- if isinstance(uri, unicode):
+ if unicode and isinstance(uri, unicode):
uri = uri.encode('ISO-8859-1')
# get the url