diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-26 23:38:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-26 23:38:56 (GMT) |
commit | 2f3ca9f20efad37aad479d557c282e08481602d0 (patch) | |
tree | 1830560daa4865d29734aa3c538eacd3199e110e /Lib/encodings | |
parent | cc9695643fc40780f51719d5e9a272283a743077 (diff) | |
download | cpython-2f3ca9f20efad37aad479d557c282e08481602d0.zip cpython-2f3ca9f20efad37aad479d557c282e08481602d0.tar.gz cpython-2f3ca9f20efad37aad479d557c282e08481602d0.tar.bz2 |
Close #13247: Add cp65001 codec, the Windows UTF-8 (CP_UTF8)
Diffstat (limited to 'Lib/encodings')
-rw-r--r-- | Lib/encodings/cp65001.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/encodings/cp65001.py b/Lib/encodings/cp65001.py new file mode 100644 index 0000000..287eb87 --- /dev/null +++ b/Lib/encodings/cp65001.py @@ -0,0 +1,40 @@ +""" +Code page 65001: Windows UTF-8 (CP_UTF8). +""" + +import codecs +import functools + +if not hasattr(codecs, 'code_page_encode'): + raise LookupError("cp65001 encoding is only available on Windows") + +### Codec APIs + +encode = functools.partial(codecs.code_page_encode, 65001) +decode = functools.partial(codecs.code_page_decode, 65001) + +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = decode + +class StreamWriter(codecs.StreamWriter): + encode = encode + +class StreamReader(codecs.StreamReader): + decode = decode + +### encodings module API + +def getregentry(): + return codecs.CodecInfo( + name='cp65001', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) |