openmedialibrary_platform/Darwin/lib/python3.5/encodings/cp65001.py

44 lines
1.1 KiB
Python
Raw Normal View History

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)
2015-11-25 01:25:01 +00:00
_decode = functools.partial(codecs.code_page_decode, 65001)
def decode(input, errors='strict'):
return codecs.code_page_decode(65001, input, errors, True)
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):
2015-11-25 01:25:01 +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):
2015-11-25 01:25:01 +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,
)