mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
Issue #5915: Implement PEP 383, Non-decodable Bytes in
System Character Interfaces.
This commit is contained in:
parent
93f65a177b
commit
011e842033
15 changed files with 726 additions and 289 deletions
|
@ -1516,6 +1516,34 @@ class TypesTest(unittest.TestCase):
|
|||
self.assertEquals(codecs.raw_unicode_escape_decode(r"\u1234"), ("\u1234", 6))
|
||||
self.assertEquals(codecs.raw_unicode_escape_decode(br"\u1234"), ("\u1234", 6))
|
||||
|
||||
class Utf8bTest(unittest.TestCase):
|
||||
|
||||
def test_utf8(self):
|
||||
# Bad byte
|
||||
self.assertEqual(b"foo\x80bar".decode("utf-8", "utf8b"),
|
||||
"foo\udc80bar")
|
||||
self.assertEqual("foo\udc80bar".encode("utf-8", "utf8b"),
|
||||
b"foo\x80bar")
|
||||
# bad-utf-8 encoded surrogate
|
||||
self.assertEqual(b"\xed\xb0\x80".decode("utf-8", "utf8b"),
|
||||
"\udced\udcb0\udc80")
|
||||
self.assertEqual("\udced\udcb0\udc80".encode("utf-8", "utf8b"),
|
||||
b"\xed\xb0\x80")
|
||||
|
||||
def test_ascii(self):
|
||||
# bad byte
|
||||
self.assertEqual(b"foo\x80bar".decode("ascii", "utf8b"),
|
||||
"foo\udc80bar")
|
||||
self.assertEqual("foo\udc80bar".encode("ascii", "utf8b"),
|
||||
b"foo\x80bar")
|
||||
|
||||
def test_charmap(self):
|
||||
# bad byte: \xa5 is unmapped in iso-8859-3
|
||||
self.assertEqual(b"foo\xa5bar".decode("iso-8859-3", "utf8b"),
|
||||
"foo\udca5bar")
|
||||
self.assertEqual("foo\udca5bar".encode("iso-8859-3", "utf8b"),
|
||||
b"foo\xa5bar")
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(
|
||||
|
@ -1543,6 +1571,7 @@ def test_main():
|
|||
CharmapTest,
|
||||
WithStmtTest,
|
||||
TypesTest,
|
||||
Utf8bTest,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue