|
2 | 2 | import sys, codecs, html.entities, unicodedata |
3 | 3 | import ctypes |
4 | 4 |
|
| 5 | +SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar) |
| 6 | + |
5 | 7 | class PosReturn: |
6 | 8 | # this can be used for configurable callbacks |
7 | 9 |
|
@@ -206,7 +208,7 @@ def test_decodeunicodeinternal(self): |
206 | 208 | b"\x00\x00\x00\x00\x00".decode, |
207 | 209 | "unicode-internal", |
208 | 210 | ) |
209 | | - if sys.maxunicode > 0xffff: |
| 211 | + if SIZEOF_WCHAR_T == 4: |
210 | 212 | def handler_unicodeinternal(exc): |
211 | 213 | if not isinstance(exc, UnicodeDecodeError): |
212 | 214 | raise TypeError("don't know how to handle %r" % exc) |
@@ -356,7 +358,7 @@ def test_unicodeencodeerror(self): |
356 | 358 | ["ascii", "\uffffx", 0, 1, "ouch"], |
357 | 359 | "'ascii' codec can't encode character '\\uffff' in position 0: ouch" |
358 | 360 | ) |
359 | | - if sys.maxunicode > 0xffff: |
| 361 | + if SIZEOF_WCHAR_T == 4: |
360 | 362 | self.check_exceptionobjectargs( |
361 | 363 | UnicodeEncodeError, |
362 | 364 | ["ascii", "\U00010000x", 0, 1, "ouch"], |
@@ -391,7 +393,7 @@ def test_unicodetranslateerror(self): |
391 | 393 | ["g\uffffrk", 1, 2, "ouch"], |
392 | 394 | "can't translate character '\\uffff' in position 1: ouch" |
393 | 395 | ) |
394 | | - if sys.maxunicode > 0xffff: |
| 396 | + if SIZEOF_WCHAR_T == 4: |
395 | 397 | self.check_exceptionobjectargs( |
396 | 398 | UnicodeTranslateError, |
397 | 399 | ["g\U00010000rk", 1, 2, "ouch"], |
@@ -682,7 +684,7 @@ def test_xmlcharrefvalues(self): |
682 | 684 | # Python/codecs.c::PyCodec_XMLCharRefReplaceErrors() |
683 | 685 | # and inline implementations |
684 | 686 | v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000) |
685 | | - if sys.maxunicode>=100000: |
| 687 | + if SIZEOF_WCHAR_T == 4: |
686 | 688 | v += (100000, 500000, 1000000) |
687 | 689 | s = "".join([chr(x) for x in v]) |
688 | 690 | codecs.register_error("test.xmlcharrefreplace", codecs.xmlcharrefreplace_errors) |
|
0 commit comments