blob: 77f408b2dcd753f32ef440fd7dd9c0725ec88881 [file] [log] [blame]
Marc-André Lemburgef342742001-01-10 10:21:11 +00001""" Test Codecs (used by test_charmapcodec)
2
3Written by Marc-Andre Lemburg (mal@lemburg.com).
4
5(c) Copyright 2000 Guido van Rossum.
6
7"""#"
8import codecs
9
10### Codec APIs
11
12class Codec(codecs.Codec):
13
14 def encode(self,input,errors='strict'):
15
16 return codecs.charmap_encode(input,errors,encoding_map)
Tim Petersd2bf3b72001-01-18 02:22:22 +000017
Marc-André Lemburgef342742001-01-10 10:21:11 +000018 def decode(self,input,errors='strict'):
19
20 return codecs.charmap_decode(input,errors,decoding_map)
21
22class StreamWriter(Codec,codecs.StreamWriter):
23 pass
Tim Petersd2bf3b72001-01-18 02:22:22 +000024
Marc-André Lemburgef342742001-01-10 10:21:11 +000025class StreamReader(Codec,codecs.StreamReader):
26 pass
27
28### encodings module API
29
30def getregentry():
31
32 return (Codec().encode,Codec().decode,StreamReader,StreamWriter)
33
34### Decoding Map
35
36decoding_map = codecs.make_identity_dict(range(256))
37decoding_map.update({
Guido van Rossumef87d6e2007-05-02 19:09:54 +000038 0x78: "abc", # 1-n decoding mapping
Guido van Rossum98297ee2007-11-06 21:34:58 +000039 b"abc": 0x0078,# 1-n encoding mapping
Marc-André Lemburgef342742001-01-10 10:21:11 +000040 0x01: None, # decoding mapping to <undefined>
Guido van Rossumef87d6e2007-05-02 19:09:54 +000041 0x79: "", # decoding mapping to <remove character>
Marc-André Lemburgef342742001-01-10 10:21:11 +000042})
43
44### Encoding Map
45
46encoding_map = {}
47for k,v in decoding_map.items():
48 encoding_map[v] = k