微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python codecs 模块-make_encoding_map() 实例源码

Python codecs 模块,make_encoding_map() 实例源码

我们从Python开源项目中,提取了以下1代码示例,用于说明如何使用codecs.make_encoding_map()

项目:tichu-tournament    作者:aragos    | 项目源码 | 文件源码
def _256_exception_codec(name,exceptions,rexceptions,baseRange=range(32,256)):
        import codecs
        decoding_map = codecs.make_identity_dict(baseRange)
        decoding_map.update(exceptions)
        encoding_map = codecs.make_encoding_map(decoding_map)
        if rexceptions: encoding_map.update(rexceptions)
        ### Codec APIs
        class Codec(codecs.Codec):
            def encode(self,input,errors='strict',charmap_encode=codecs.charmap_encode,encoding_map=encoding_map):
                return charmap_encode(input,errors,encoding_map)

            def decode(self,charmap_decode=codecs.charmap_decode,decoding_map=decoding_map):
                return charmap_decode(input,decoding_map)

        class StreamWriter(Codec,codecs.StreamWriter):
            pass

        class StreamReader(Codec,codecs.StreamReader):
            pass
        C = Codec()
        return codecs.CodecInfo(C.encode,C.decode,streamreader=StreamReader,streamwriter=StreamWriter,name=name)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐