ยปCore Development>Code coverage>Lib/test/testcodec.py

Python code coverage for Lib/test/testcodec.py

#countcontent
1n/a""" Test Codecs (used by test_charmapcodec)
2n/a
3n/aWritten by Marc-Andre Lemburg (mal@lemburg.com).
4n/a
5n/a(c) Copyright 2000 Guido van Rossum.
6n/a
7n/a"""#"
8n/aimport codecs
9n/a
10n/a### Codec APIs
11n/a
12n/aclass Codec(codecs.Codec):
13n/a
14n/a def encode(self,input,errors='strict'):
15n/a
16n/a return codecs.charmap_encode(input,errors,encoding_map)
17n/a
18n/a def decode(self,input,errors='strict'):
19n/a
20n/a return codecs.charmap_decode(input,errors,decoding_map)
21n/a
22n/aclass StreamWriter(Codec,codecs.StreamWriter):
23n/a pass
24n/a
25n/aclass StreamReader(Codec,codecs.StreamReader):
26n/a pass
27n/a
28n/a### encodings module API
29n/a
30n/adef getregentry():
31n/a
32n/a return (Codec().encode,Codec().decode,StreamReader,StreamWriter)
33n/a
34n/a### Decoding Map
35n/a
36n/adecoding_map = codecs.make_identity_dict(range(256))
37n/adecoding_map.update({
38n/a 0x78: "abc", # 1-n decoding mapping
39n/a b"abc": 0x0078,# 1-n encoding mapping
40n/a 0x01: None, # decoding mapping to <undefined>
41n/a 0x79: "", # decoding mapping to <remove character>
42n/a})
43n/a
44n/a### Encoding Map
45n/a
46n/aencoding_map = {}
47n/afor k,v in decoding_map.items():
48n/a encoding_map[v] = k