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> """ # sys.setdefaultencoding() normally doesn't exist after site.py is # loaded. Import a temporary fresh copy to get access to it # but then restore the original copy to avoid messing with # other potentially modified sys module attributes old_encoding = sys.getdefaultencoding() with test_support.CleanImport('sys'): import sys as temp_sys temp_sys.setdefaultencoding("iso-8859-1") try: (s, d), m = xmlrpclib.loads(utf8) finally: temp_sys.setdefaultencoding(old_encoding) items = d.items() if have_unicode: self.assertEqual(s, u"abc \x95") self.assertIsInstance(s, unicode) self.assertEqual(items, [(u"def \x96", u"ghi \x97")]) self.assertIsInstance(items[0][0], unicode) self.assertIsInstance(items[0][1], unicode) else: self.assertEqual(s, "abc \xc2\x95") self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")])
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)