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