1""" 2Code page 65001: Windows UTF-8 (CP_UTF8). 3""" 4 5import codecs 6import functools 7 8if not hasattr(codecs, 'code_page_encode'): 9 raise LookupError("cp65001 encoding is only available on Windows") 10 11### Codec APIs 12 13encode = functools.partial(codecs.code_page_encode, 65001) 14_decode = functools.partial(codecs.code_page_decode, 65001) 15 16def decode(input, errors='strict'): 17 return codecs.code_page_decode(65001, input, errors, True) 18 19class IncrementalEncoder(codecs.IncrementalEncoder): 20 def encode(self, input, final=False): 21 return encode(input, self.errors)[0] 22 23class IncrementalDecoder(codecs.BufferedIncrementalDecoder): 24 _buffer_decode = _decode 25 26class StreamWriter(codecs.StreamWriter): 27 encode = encode 28 29class StreamReader(codecs.StreamReader): 30 decode = _decode 31 32### encodings module API 33 34def getregentry(): 35 return codecs.CodecInfo( 36 name='cp65001', 37 encode=encode, 38 decode=decode, 39 incrementalencoder=IncrementalEncoder, 40 incrementaldecoder=IncrementalDecoder, 41 streamreader=StreamReader, 42 streamwriter=StreamWriter, 43 ) 44