2013-10-11 17:28:32 +00:00
|
|
|
"""
|
2014-09-30 16:15:32 +00:00
|
|
|
Code page 65001: Windows UTF-8 (CP_UTF8).
|
2013-10-11 17:28:32 +00:00
|
|
|
"""
|
2014-09-30 16:15:32 +00:00
|
|
|
|
2013-10-11 17:28:32 +00:00
|
|
|
import codecs
|
2014-09-30 16:15:32 +00:00
|
|
|
import functools
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
if not hasattr(codecs, 'code_page_encode'):
|
|
|
|
raise LookupError("cp65001 encoding is only available on Windows")
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
### Codec APIs
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
encode = functools.partial(codecs.code_page_encode, 65001)
|
|
|
|
decode = functools.partial(codecs.code_page_decode, 65001)
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
class IncrementalEncoder(codecs.IncrementalEncoder):
|
|
|
|
def encode(self, input, final=False):
|
2014-09-30 16:15:32 +00:00
|
|
|
return encode(input, self.errors)[0]
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
2014-09-30 16:15:32 +00:00
|
|
|
_buffer_decode = decode
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
class StreamWriter(codecs.StreamWriter):
|
2014-09-30 16:15:32 +00:00
|
|
|
encode = encode
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
class StreamReader(codecs.StreamReader):
|
2014-09-30 16:15:32 +00:00
|
|
|
decode = decode
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
### encodings module API
|
|
|
|
|
|
|
|
def getregentry():
|
|
|
|
return codecs.CodecInfo(
|
2014-09-30 16:15:32 +00:00
|
|
|
name='cp65001',
|
2013-10-11 17:28:32 +00:00
|
|
|
encode=encode,
|
|
|
|
decode=decode,
|
|
|
|
incrementalencoder=IncrementalEncoder,
|
|
|
|
incrementaldecoder=IncrementalDecoder,
|
|
|
|
streamreader=StreamReader,
|
|
|
|
streamwriter=StreamWriter,
|
|
|
|
)
|