0001 """ Test Codecs (used by test_charmapcodec) 0002 0003 Written by Marc-Andre Lemburg (mal@lemburg.com). 0004 0005 (c) Copyright 2000 Guido van Rossum. 0006 0007 """#" 0008 import codecs 0009 0010 ### Codec APIs 0011 0012 class Codec(codecs.Codec): 0013 0014 def encode(self,input,errors='strict'): 0015 0016 return codecs.charmap_encode(input,errors,encoding_map) 0017 0018 def decode(self,input,errors='strict'): 0019 0020 return codecs.charmap_decode(input,errors,decoding_map) 0021 0022 class StreamWriter(Codec,codecs.StreamWriter): 0023 pass 0024 0025 class StreamReader(Codec,codecs.StreamReader): 0026 pass 0027 0028 ### encodings module API 0029 0030 def getregentry(): 0031 0032 return (Codec().encode,Codec().decode,StreamReader,StreamWriter) 0033 0034 ### Decoding Map 0035 0036 decoding_map = codecs.make_identity_dict(range(256)) 0037 decoding_map.update({ 0038 0x78: u"abc", # 1-n decoding mapping 0039 "abc": 0x0078,# 1-n encoding mapping 0040 0x01: None, # decoding mapping to <undefined> 0041 0x79: u"", # decoding mapping to <remove character> 0042 }) 0043 0044 ### Encoding Map 0045 0046 encoding_map = {} 0047 for k,v in decoding_map.items(): 0048 encoding_map[v] = k 0049
Generated by PyXR 0.9.4