summaryrefslogtreecommitdiffstats
path: root/Lib/encodings
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-26 23:38:56 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-26 23:38:56 (GMT)
commit2f3ca9f20efad37aad479d557c282e08481602d0 (patch)
tree1830560daa4865d29734aa3c538eacd3199e110e /Lib/encodings
parentcc9695643fc40780f51719d5e9a272283a743077 (diff)
downloadcpython-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.py40
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,
+ )