summaryrefslogtreecommitdiffstats
path: root/generic/tclMain.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclMain.c')
-rw-r--r--generic/tclMain.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/generic/tclMain.c b/generic/tclMain.c
index 4a66793..f789370 100644
--- a/generic/tclMain.c
+++ b/generic/tclMain.c
@@ -71,7 +71,7 @@ NewNativeObj(
#ifdef UNICODE
Tcl_DStringInit(&ds);
- Tcl_WCharToUtfDString(string, length, &ds);
+ Tcl_Char16ToUtfDString(string, length, &ds);
#else
Tcl_ExternalToUtfDString(NULL, (char *) string, length, &ds);
#endif
kwa">if not data: break e = encoder.encode(data) ostream.write(e) self.assertEqual(ostream.getvalue(), self.tstring[0]) def test_incrementaldecoder(self): UTF8Writer = codecs.getwriter('utf-8') for sizehint in [None, -1] + list(range(1, 33)) + \ [64, 128, 256, 512, 1024]: istream = BytesIO(self.tstring[0]) ostream = UTF8Writer(BytesIO()) decoder = self.incrementaldecoder() while 1: data = istream.read(sizehint) if not data: break else: u = decoder.decode(data) ostream.write(u) self.assertEqual(ostream.getvalue(), self.tstring[1]) def test_incrementalencoder_error_callback(self): inv = self.unmappedunicode e = self.incrementalencoder() self.assertRaises(UnicodeEncodeError, e.encode, inv, True) e.errors = 'ignore' self.assertEqual(e.encode(inv, True), b'') e.reset() def tempreplace(exc): return ('called', exc.end) codecs.register_error('test.incremental_error_callback', tempreplace) e.errors = 'test.incremental_error_callback' self.assertEqual(e.encode(inv, True), b'called') # again e.errors = 'ignore' self.assertEqual(e.encode(inv, True), b'') def test_streamreader(self): UTF8Writer = codecs.getwriter('utf-8') for name in ["read", "readline", "readlines"]: for sizehint in [None, -1] + list(range(1, 33)) + \ [64, 128, 256, 512, 1024]: istream = self.reader(BytesIO(self.tstring[0])) ostream = UTF8Writer(BytesIO()) func = getattr(istream, name) while 1: data = func(sizehint) if not data: break if name == "readlines": ostream.writelines(data) else: ostream.write(data) self.assertEqual(ostream.getvalue(), self.tstring[1]) def test_streamwriter(self): readfuncs = ('read', 'readline', 'readlines') UTF8Reader = codecs.getreader('utf-8') for name in readfuncs: for sizehint in [None] + list(range(1, 33)) + \ [64, 128, 256, 512, 1024]: istream = UTF8Reader(BytesIO(self.tstring[1])) ostream = self.writer(BytesIO()) func = getattr(istream, name) while 1: if sizehint is not None: data = func(sizehint) else: data = func() if not data: break if name == "readlines": ostream.writelines(data) else: ostream.write(data) self.assertEqual(ostream.getvalue(), self.tstring[0]) class TestBase_Mapping(unittest.TestCase): pass_enctest = [] pass_dectest = [] supmaps = [] codectests = [] def __init__(self, *args, **kw): unittest.TestCase.__init__(self, *args, **kw) try: self.open_mapping_file().close() # test it to report the error early except (IOError, HTTPException): self.skipTest("Could not retrieve "+self.mapfileurl) def open_mapping_file(self): return support.open_urlresource(self.mapfileurl) def test_mapping_file(self): if self.mapfileurl.endswith('.xml'): self._test_mapping_file_ucm() else: self._test_mapping_file_plain() def _test_mapping_file_plain(self): unichrs = lambda s: ''.join(map(chr, map(eval, s.split('+')))) urt_wa = {} with self.open_mapping_file() as f: for line in f: if not line: break data = line.split('#')[0].strip().split() if len(data) != 2: continue csetval = eval(data[0]) if csetval <= 0x7F: csetch = bytes([csetval & 0xff]) elif csetval >= 0x1000000: csetch = bytes([(csetval >> 24), ((csetval >> 16) & 0xff), ((csetval >> 8) & 0xff), (csetval & 0xff)]) elif csetval >= 0x10000: csetch = bytes([(csetval >> 16), ((csetval >> 8) & 0xff), (csetval & 0xff)]) elif csetval >= 0x100: csetch = bytes([(csetval >> 8), (csetval & 0xff)]) else: continue unich = unichrs(data[1]) if ord(unich) == 0xfffd or unich in urt_wa: continue urt_wa[unich] = csetch self._testpoint(csetch, unich) def _test_mapping_file_ucm(self): with self.open_mapping_file() as f: ucmdata = f.read() uc = re.findall('<a u="([A-F0-9]{4})" b="([0-9A-F ]+)"/>', ucmdata) for uni, coded in uc: unich = chr(int(uni, 16)) codech = bytes(int(c, 16) for c in coded.split()) self._testpoint(codech, unich) def test_mapping_supplemental(self): for mapping in self.supmaps: self._testpoint(*mapping) def _testpoint(self, csetch, unich): if (csetch, unich) not in self.pass_enctest: self.assertEqual(unich.encode(self.encoding), csetch) if (csetch, unich) not in self.pass_dectest: self.assertEqual(str(csetch, self.encoding), unich) def test_errorhandle(self): for source, scheme, expected in self.codectests: if isinstance(source, bytes): func = source.decode else: func = source.encode if expected: if isinstance(source, bytes): result = func(self.encoding, scheme) self.assertTrue(type(result) is str, type(result)) self.assertEqual(result, expected, '%a.decode(%r, %r)=%a != %a' % (source, self.encoding, scheme, result, expected)) else: result = func(self.encoding, scheme) self.assertTrue(type(result) is bytes, type(result)) self.assertEqual(result, expected, '%a.encode(%r, %r)=%a != %a' % (source, self.encoding, scheme, result, expected)) else: self.assertRaises(UnicodeError, func, self.encoding, scheme) def load_teststring(name): dir = os.path.join(os.path.dirname(__file__), 'cjkencodings') with open(os.path.join(dir, name + '.txt'), 'rb') as f: encoded = f.read() with open(os.path.join(dir, name + '-utf8.txt'), 'rb') as f: utf8 = f.read() return encoded, utf8