Python codecs.make_encoding_map() Examples

The following are 2 code examples of codecs.make_encoding_map(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module codecs , or try the search function .
Example #1
Source File: rl_codecs.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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,input,errors='strict',charmap_decode=codecs.charmap_decode,decoding_map=decoding_map):
                return charmap_decode(input,errors,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) 
Example #2
Source File: rl_codecs.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def _256_exception_codec(xt):
        exceptions,rexceptions = xt
        import codecs
        decoding_map = codecs.make_identity_dict(xrange(32,256))
        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,input,errors='strict',charmap_decode=codecs.charmap_decode,decoding_map=decoding_map):
                return charmap_decode(input,errors,decoding_map)

        class StreamWriter(Codec,codecs.StreamWriter):
            pass

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