1 | n/a | """ Python 'unicode-escape' Codec |
---|
2 | n/a | |
---|
3 | n/a | |
---|
4 | n/a | Written by Marc-Andre Lemburg (mal@lemburg.com). |
---|
5 | n/a | |
---|
6 | n/a | (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
---|
7 | n/a | |
---|
8 | n/a | """ |
---|
9 | n/a | import codecs |
---|
10 | n/a | |
---|
11 | n/a | ### Codec APIs |
---|
12 | n/a | |
---|
13 | n/a | class Codec(codecs.Codec): |
---|
14 | n/a | |
---|
15 | n/a | # Note: Binding these as C functions will result in the class not |
---|
16 | n/a | # converting them to methods. This is intended. |
---|
17 | n/a | encode = codecs.unicode_escape_encode |
---|
18 | n/a | decode = codecs.unicode_escape_decode |
---|
19 | n/a | |
---|
20 | n/a | class IncrementalEncoder(codecs.IncrementalEncoder): |
---|
21 | n/a | def encode(self, input, final=False): |
---|
22 | n/a | return codecs.unicode_escape_encode(input, self.errors)[0] |
---|
23 | n/a | |
---|
24 | n/a | class IncrementalDecoder(codecs.IncrementalDecoder): |
---|
25 | n/a | def decode(self, input, final=False): |
---|
26 | n/a | return codecs.unicode_escape_decode(input, self.errors)[0] |
---|
27 | n/a | |
---|
28 | n/a | class StreamWriter(Codec,codecs.StreamWriter): |
---|
29 | n/a | pass |
---|
30 | n/a | |
---|
31 | n/a | class StreamReader(Codec,codecs.StreamReader): |
---|
32 | n/a | pass |
---|
33 | n/a | |
---|
34 | n/a | ### encodings module API |
---|
35 | n/a | |
---|
36 | n/a | def getregentry(): |
---|
37 | n/a | return codecs.CodecInfo( |
---|
38 | n/a | name='unicode-escape', |
---|
39 | n/a | encode=Codec.encode, |
---|
40 | n/a | decode=Codec.decode, |
---|
41 | n/a | incrementalencoder=IncrementalEncoder, |
---|
42 | n/a | incrementaldecoder=IncrementalDecoder, |
---|
43 | n/a | streamwriter=StreamWriter, |
---|
44 | n/a | streamreader=StreamReader, |
---|
45 | n/a | ) |
---|