Back to index

python3.2  3.2.2
Public Member Functions
test.test_codecs.UnicodeInternalTest Class Reference

List of all members.

Public Member Functions

def test_bug1251300
def test_decode_error_attributes
def test_decode_callback
def test_encode_length

Detailed Description

Definition at line 886 of file test_codecs.py.


Member Function Documentation

Definition at line 887 of file test_codecs.py.

00887 
00888     def test_bug1251300(self):
00889         # Decoding with unicode_internal used to not correctly handle "code
00890         # points" above 0x10ffff on UCS-4 builds.
00891         if sys.maxunicode > 0xffff:
00892             ok = [
00893                 (b"\x00\x10\xff\xff", "\U0010ffff"),
00894                 (b"\x00\x00\x01\x01", "\U00000101"),
00895                 (b"", ""),
00896             ]
00897             not_ok = [
00898                 b"\x7f\xff\xff\xff",
00899                 b"\x80\x00\x00\x00",
00900                 b"\x81\x00\x00\x00",
00901                 b"\x00",
00902                 b"\x00\x00\x00\x00\x00",
00903             ]
00904             for internal, uni in ok:
00905                 if sys.byteorder == "little":
00906                     internal = bytes(reversed(internal))
00907                 self.assertEqual(uni, internal.decode("unicode_internal"))
00908             for internal in not_ok:
00909                 if sys.byteorder == "little":
00910                     internal = bytes(reversed(internal))
00911                 self.assertRaises(UnicodeDecodeError, internal.decode,
00912                     "unicode_internal")

Here is the call graph for this function:

Definition at line 925 of file test_codecs.py.

00925 
00926     def test_decode_callback(self):
00927         if sys.maxunicode > 0xffff:
00928             codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
00929             decoder = codecs.getdecoder("unicode_internal")
00930             ab = "ab".encode("unicode_internal").decode()
00931             ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]),
00932                                     "ascii"),
00933                               "UnicodeInternalTest")
00934             self.assertEqual(("ab", 12), ignored)

Here is the call graph for this function:

Definition at line 913 of file test_codecs.py.

00913 
00914     def test_decode_error_attributes(self):
00915         if sys.maxunicode > 0xffff:
00916             try:
00917                 b"\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal")
00918             except UnicodeDecodeError as ex:
00919                 self.assertEqual("unicode_internal", ex.encoding)
00920                 self.assertEqual(b"\x00\x00\x00\x00\x00\x11\x11\x00", ex.object)
00921                 self.assertEqual(4, ex.start)
00922                 self.assertEqual(8, ex.end)
00923             else:
00924                 self.fail()

Here is the call graph for this function:

Definition at line 935 of file test_codecs.py.

00935 
00936     def test_encode_length(self):
00937         # Issue 3739
00938         encoder = codecs.getencoder("unicode_internal")
00939         self.assertEqual(encoder("a")[1], 1)
00940         self.assertEqual(encoder("\xe9\u0142")[1], 2)
00941 
00942         self.assertEqual(codecs.escape_encode(br'\x00')[1], 4)
00943 
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html

Here is the call graph for this function:


The documentation for this class was generated from the following file: