Lines Matching refs:codecs
1 import codecs
50 d = codecs.getincrementaldecoder(encoding)()
65 d = codecs.getincrementaldecoder(encoding)()
72 d = codecs.getincrementalencoder(encoding)()
75 d = codecs.getincrementalencoder(encoding)()
88 r = codecs.getreader(self.encoding)(q)
99 d = codecs.getincrementaldecoder(self.encoding)()
122 "".join(codecs.iterdecode([bytes([c]) for c in encoded], self.encoding))
128 return codecs.getreader(self.encoding)(stream)
192 return codecs.getreader(self.encoding)(stream)
297 reader = codecs.getreader(self.encoding)(stream)
303 writer = codecs.getwriter(self.encoding)(q)
304 reader = codecs.getreader(self.encoding)(q)
335 reader = codecs.getreader(self.encoding)(stream)
350 reader = codecs.getreader(self.encoding)(stream)
420 _,_,reader,writer = codecs.lookup(self.encoding)
436 f = codecs.getreader(self.encoding)(s)
440 f = codecs.getreader(self.encoding)(s)
476 codecs.utf_32_decode(b'\x01', 'replace', True))
478 codecs.utf_32_decode(b'\x01', 'ignore', True))
481 self.assertRaises(UnicodeDecodeError, codecs.utf_32_decode,
495 codecs.utf_32_decode(encoded_le)[0])
498 codecs.utf_32_decode(encoded_be)[0])
536 self.assertRaises(UnicodeDecodeError, codecs.utf_32_le_decode,
544 codecs.utf_32_le_decode(encoded)[0])
582 self.assertRaises(UnicodeDecodeError, codecs.utf_32_be_decode,
590 codecs.utf_32_be_decode(encoded)[0])
604 _,_,reader,writer = codecs.lookup(self.encoding)
620 f = codecs.getreader(self.encoding)(s)
624 f = codecs.getreader(self.encoding)(s)
650 codecs.utf_16_decode(b'\x01', 'replace', True))
652 codecs.utf_16_decode(b'\x01', 'ignore', True))
655 self.assertRaises(UnicodeDecodeError, codecs.utf_16_decode,
675 reader = codecs.open(support.TESTFN, 'U', encoding=self.encoding)
713 self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
757 self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
837 self.assertTrue(codecs.lookup_error("surrogatepass"))
930 self.assertTrue(codecs.lookup_error("surrogatepass"))
1026 self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode,
1069 self.assertRaises(UnicodeDecodeError, codecs.utf_16_ex_decode, b"\xff", "strict", 0, True)
1072 self.assertRaises(TypeError, codecs.utf_16_ex_decode)
1079 codecs.readbuffer_encode(array.array("b", b"spam")),
1084 self.assertEqual(codecs.readbuffer_encode(""), (b"", 0))
1087 self.assertRaises(TypeError, codecs.readbuffer_encode)
1088 self.assertRaises(TypeError, codecs.readbuffer_encode, 42)
1092 BOM = codecs.BOM_UTF8
1127 d = codecs.getincrementaldecoder("utf-8-sig")()
1133 bytestring = codecs.BOM_UTF8 + b"ABC\xC2\xA1\xE2\x88\x80XYZ"
1135 reader = codecs.getreader("utf-8-sig")
1157 reader = codecs.getreader("utf-8-sig")
1177 self.assertEqual(codecs.escape_decode(b""), (b"", 0))
1178 self.assertEqual(codecs.escape_decode(bytearray()), (b"", 0))
1181 decode = codecs.escape_decode
1188 decode = codecs.escape_decode
1225 decode = codecs.escape_decode
1239 f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
1437 codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
1438 decoder = codecs.getdecoder("unicode_internal")
1451 encoder = codecs.getencoder("unicode_internal")
1455 self.assertEqual(codecs.escape_encode(br'\x00')[1], 4)
1645 r = codecs.getreader("idna")(io.BytesIO(b"abc"))
1651 "".join(codecs.iterdecode((bytes([c]) for c in b"python.org"), "idna")),
1655 "".join(codecs.iterdecode((bytes([c]) for c in b"python.org."), "idna")),
1659 "".join(codecs.iterdecode((bytes([c]) for c in b"xn--pythn-mua.org."), "idna")),
1663 "".join(codecs.iterdecode((bytes([c]) for c in b"xn--pythn-mua.org."), "idna")),
1667 decoder = codecs.getincrementaldecoder("idna")()
1681 b"".join(codecs.iterencode("python.org", "idna")),
1685 b"".join(codecs.iterencode("python.org.", "idna")),
1689 b"".join(codecs.iterencode("pyth\xf6n.org.", "idna")),
1693 b"".join(codecs.iterencode("pyth\xf6n.org.", "idna")),
1697 encoder = codecs.getincrementalencoder("idna")()
1721 self.assertEqual(codecs.decode(b'\xe4\xf6\xfc', 'latin-1'),
1723 self.assertRaises(TypeError, codecs.decode)
1724 self.assertEqual(codecs.decode(b'abc'), 'abc')
1725 self.assertRaises(UnicodeDecodeError, codecs.decode, b'\xff', 'ascii')
1728 self.assertEqual(codecs.decode(obj=b'\xe4\xf6\xfc', encoding='latin-1'),
1730 self.assertEqual(codecs.decode(b'[\xff]', 'ascii', errors='ignore'),
1734 self.assertEqual(codecs.encode('\xe4\xf6\xfc', 'latin-1'),
1736 self.assertRaises(TypeError, codecs.encode)
1737 self.assertRaises(LookupError, codecs.encode, "foo", "__spam__")
1738 self.assertEqual(codecs.encode('abc'), b'abc')
1739 self.assertRaises(UnicodeEncodeError, codecs.encode, '\xffff', 'ascii')
1742 self.assertEqual(codecs.encode(obj='\xe4\xf6\xfc', encoding='latin-1'),
1744 self.assertEqual(codecs.encode('[\xff]', 'ascii', errors='ignore'),
1748 self.assertRaises(TypeError, codecs.register)
1749 self.assertRaises(TypeError, codecs.register, 42)
1752 self.assertRaises(TypeError, codecs.lookup)
1753 self.assertRaises(LookupError, codecs.lookup, "__spam__")
1754 self.assertRaises(LookupError, codecs.lookup, " ")
1757 self.assertRaises(TypeError, codecs.getencoder)
1758 self.assertRaises(LookupError, codecs.getencoder, "__spam__")
1761 self.assertRaises(TypeError, codecs.getdecoder)
1762 self.assertRaises(LookupError, codecs.getdecoder, "__spam__")
1765 self.assertRaises(TypeError, codecs.getreader)
1766 self.assertRaises(LookupError, codecs.getreader, "__spam__")
1769 self.assertRaises(TypeError, codecs.getwriter)
1770 self.assertRaises(LookupError, codecs.getwriter, "__spam__")
1782 c = codecs.lookup('ASCII')
1804 self.assertCountEqual(api, codecs.__all__)
1805 for api in codecs.__all__:
1806 getattr(codecs, api)
1812 codecs.open(support.TESTFN, mode, 'ascii') as file:
1813 self.assertIsInstance(file, codecs.StreamReaderWriter)
1816 self.assertRaises(UnicodeError, codecs.encode, 'abc', 'undefined')
1817 self.assertRaises(UnicodeError, codecs.decode, b'abc', 'undefined')
1818 self.assertRaises(UnicodeError, codecs.encode, '', 'undefined')
1819 self.assertRaises(UnicodeError, codecs.decode, b'', 'undefined')
1822 codecs.encode, 'abc', 'undefined', errors)
1824 codecs.decode, b'abc', 'undefined', errors)
1830 self.reader = codecs.getreader('utf-8')
1842 ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
1846 ef = codecs.EncodedFile(f, 'utf-8', 'latin-1')
1955 if hasattr(codecs, "mbcs_encode"):
1957 if hasattr(codecs, "oem_encode"):
1975 name = codecs.lookup(encoding).name
1984 (b, size) = codecs.getencoder(encoding)(s)
1986 (chars, size) = codecs.getdecoder(encoding)(b)
1992 writer = codecs.getwriter(encoding)(q)
2000 reader = codecs.getreader(encoding)(q)
2010 encoder = codecs.getincrementalencoder(encoding)()
2019 decoder = codecs.getincrementaldecoder(encoding)()
2028 result = "".join(codecs.iterdecode(
2029 codecs.iterencode(s, encoding), encoding))
2033 result = "".join(codecs.iterdecode(
2034 codecs.iterencode("", encoding), encoding))
2040 encoder = codecs.getincrementalencoder(encoding)("ignore")
2045 decoder = codecs.getincrementaldecoder(encoding)("ignore")
2098 reader = codecs.getreader(encoding)(io.BytesIO(s.encode(encoding)))
2107 decoder = codecs.getdecoder(encoding)
2114 encoder = codecs.getencoder(encoding)
2137 codecs.charmap_decode(b"\x00\x01\x02", "strict", "abc"),
2142 codecs.charmap_decode(b"\x00\x01\x02", "strict", "\U0010FFFFbc"),
2147 codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab"
2151 codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab\ufffe"
2155 codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab"),
2160 codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab\ufffe"),
2165 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace", "ab"),
2170 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace", "ab\ufffe"),
2175 codecs.charmap_decode(b"\x00\x01\x02", "ignore", "ab"),
2180 codecs.charmap_decode(b"\x00\x01\x02", "ignore", "ab\ufffe"),
2186 codecs.charmap_decode(allbytes, "ignore", ""),
2192 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2198 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2204 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2210 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2216 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2221 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2227 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2232 codecs.charmap_decode(b"\x00\x01\x02", "replace",
2238 codecs.charmap_decode(b"\x00\x01\x02", "replace",
2245 codecs.charmap_decode(b"\x00\x01\x02", "replace",
2251 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace",
2257 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace",
2264 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace",
2270 codecs.charmap_decode(b"\x00\x01\x02", "ignore",
2276 codecs.charmap_decode(b"\x00\x01\x02", "ignore",
2283 codecs.charmap_decode(b"\x00\x01\x02", "ignore",
2290 codecs.charmap_decode(allbytes, "ignore", {}),
2300 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2307 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2313 codecs.charmap_decode(b"\x00\x01\x02", "strict",
2319 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2324 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2329 codecs.charmap_decode, b"\x00\x01\x02", "strict",
2334 codecs.charmap_decode(b"\x00\x01\x02", "replace",
2340 codecs.charmap_decode(b"\x00\x01\x02", "replace",
2346 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace",
2352 codecs.charmap_decode(b"\x00\x01\x02", "backslashreplace",
2358 codecs.charmap_decode(b"\x00\x01\x02", "ignore",
2364 codecs.charmap_decode(b"\x00\x01\x02", "ignore",
2373 with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
2379 info = codecs.lookup("utf-8")
2380 with codecs.StreamReaderWriter(f, info.streamreader,
2389 codecs.utf_7_decode,
2390 codecs.utf_8_decode,
2391 codecs.utf_16_le_decode,
2392 codecs.utf_16_be_decode,
2393 codecs.utf_16_ex_decode,
2394 codecs.utf_32_decode,
2395 codecs.utf_32_le_decode,
2396 codecs.utf_32_be_decode,
2397 codecs.utf_32_ex_decode,
2398 codecs.latin_1_decode,
2399 codecs.ascii_decode,
2400 codecs.charmap_decode,
2402 if hasattr(codecs, "mbcs_decode"):
2403 decoders.append(codecs.mbcs_decode)
2410 self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6))
2411 self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6))
2412 self.assertEqual(codecs.raw_unicode_escape_decode(r"\u1234"), ("\u1234", 6))
2413 self.assertEqual(codecs.raw_unicode_escape_decode(br"\u1234"), ("\u1234", 6))
2415 self.assertRaises(UnicodeDecodeError, codecs.unicode_escape_decode, br"\U00110000")
2416 self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
2417 self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "backslashreplace"),
2420 self.assertRaises(UnicodeDecodeError, codecs.raw_unicode_escape_decode, br"\U00110000")
2421 self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
2422 self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "backslashreplace"),
2428 self.assertEqual(codecs.unicode_escape_encode(""), (b"", 0))
2429 self.assertEqual(codecs.unicode_escape_decode(b""), ("", 0))
2432 encode = codecs.unicode_escape_encode
2438 decode = codecs.unicode_escape_decode
2444 encode = codecs.unicode_escape_encode
2459 decode = codecs.unicode_escape_decode
2498 decode = codecs.unicode_escape_decode
2516 self.assertEqual(codecs.raw_unicode_escape_encode(""), (b"", 0))
2517 self.assertEqual(codecs.raw_unicode_escape_decode(b""), ("", 0))
2520 encode = codecs.raw_unicode_escape_encode
2525 decode = codecs.raw_unicode_escape_decode
2530 encode = codecs.raw_unicode_escape_encode
2539 decode = codecs.raw_unicode_escape_decode
2548 decode = codecs.raw_unicode_escape_decode
2579 self.assertEqual(codecs.escape_encode(data), output)
2580 self.assertRaises(TypeError, codecs.escape_encode, 'spam')
2581 self.assertRaises(TypeError, codecs.escape_encode, bytearray(b'spam'))
2630 with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
2639 with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
2648 with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
2658 with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
2667 with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
2713 (o, size) = codecs.getencoder(encoding)(binput)
2715 (i, size) = codecs.getdecoder(encoding)(o)
2722 sin = codecs.encode(b"\x80", encoding)
2723 reader = codecs.getreader(encoding)(io.BytesIO(sin))
2730 sin = codecs.encode(b"\x80", encoding)
2731 reader = codecs.getreader(encoding)(io.BytesIO(sin))
2744 data = codecs.encode(data, encoding)
2745 view_encoded = codecs.encode(view, encoding)
2748 data = codecs.decode(data, encoding)
2750 view_decoded = codecs.decode(view, encoding)
2778 encoded_data = codecs.encode(data, encoding)
2802 codecs.decode(b"hello", "zlib_codec")
2810 codecs.decode(b"hello", "hex_codec")
2820 expected_name = codecs.lookup(codec_name).name
2823 info = codecs.lookup(alias)
2828 encoded = codecs.encode(b"space tab\teol \n", "quopri-codec")
2832 self.assertEqual(codecs.decode(unescaped, "quopri-codec"), unescaped)
2836 self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")
2851 codecs.register(_get_test_codec) # Returns None, not usable as a decorator
2894 codec_info = codecs.CodecInfo(encode, decode,
2917 codecs.encode("str_input", self.codec_name)
2921 codecs.decode(b"bytes input", self.codec_name)
2949 codecs.encode("str input", self.codec_name)
2953 codecs.decode(b"bytes input", self.codec_name)
2987 codecs.encode("str input", self.codec_name)
2991 codecs.decode(b"bytes input", self.codec_name)
3005 encoded = codecs.encode(None, self.codec_name)
3007 decoded = codecs.decode(None, self.codec_name)
3030 self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a')
3031 self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a')
3032 self.assertRaises(OSError, codecs.code_page_encode, 123, 'a')
3033 self.assertRaises(OSError, codecs.code_page_decode, 123, b'a')
3037 codecs.code_page_encode, 932, '\xff')
3039 codecs.code_page_decode, 932, b'\x81\x00', 'strict', True)
3041 codecs.code_page_decode, self.CP_UTF8, b'\xff', 'strict', True)
3047 decoded = codecs.code_page_decode(cp, raw, errors, True)
3059 codecs.code_page_decode, cp, raw, errors, True)
3065 encoded = codecs.code_page_encode(cp, text, errors)
3075 codecs.code_page_encode, cp, text, errors)
3163 decoded = codecs.code_page_decode(932, b'\x82', 'strict', False)
3166 decoded = codecs.code_page_decode(932,
3171 decoded = codecs.code_page_decode(932,
3176 decoded = codecs.code_page_decode(932,
3185 codec = codecs.lookup('cp123')
3196 decoded = codecs.code_page_decode(932, encoded, 'surrogateescape', True)