|
8 | 8 |
|
9 | 9 | """
|
10 | 10 | import codecs
|
11 |
| -import bz2 # this codec needs the optional bz2 module ! |
| 11 | +import bz2 |
12 | 12 |
|
13 |
| -### Codec APIs |
14 |
| - |
15 |
| -def bz2_encode(input,errors='strict'): |
16 |
| - |
17 |
| - """ Encodes the object input and returns a tuple (output |
18 |
| - object, length consumed). |
19 |
| -
|
20 |
| - errors defines the error handling to apply. It defaults to |
21 |
| - 'strict' handling which is the only currently supported |
22 |
| - error handling for this codec. |
23 |
| -
|
24 |
| - """ |
| 13 | +def encode(input, errors='strict'): |
25 | 14 | assert errors == 'strict'
|
26 | 15 | output = bz2.compress(input)
|
27 | 16 | return (output, len(input))
|
28 | 17 |
|
29 |
| -def bz2_decode(input,errors='strict'): |
30 |
| - |
31 |
| - """ Decodes the object input and returns a tuple (output |
32 |
| - object, length consumed). |
33 |
| -
|
34 |
| - input must be an object which provides the bf_getreadbuf |
35 |
| - buffer slot. Python strings, buffer objects and memory |
36 |
| - mapped files are examples of objects providing this slot. |
37 |
| -
|
38 |
| - errors defines the error handling to apply. It defaults to |
39 |
| - 'strict' handling which is the only currently supported |
40 |
| - error handling for this codec. |
41 |
| -
|
42 |
| - """ |
| 18 | +def decode(input, errors='strict'): |
43 | 19 | assert errors == 'strict'
|
44 | 20 | output = bz2.decompress(input)
|
45 | 21 | return (output, len(input))
|
46 | 22 |
|
47 |
| -class Codec(codecs.Codec): |
48 |
| - |
49 |
| - def encode(self, input, errors='strict'): |
50 |
| - return bz2_encode(input, errors) |
51 |
| - def decode(self, input, errors='strict'): |
52 |
| - return bz2_decode(input, errors) |
53 |
| - |
54 |
| -class StreamWriter(Codec,codecs.StreamWriter): |
55 |
| - pass |
56 |
| - |
57 |
| -class StreamReader(Codec,codecs.StreamReader): |
58 |
| - pass |
59 |
| - |
60 | 23 | ### encodings module API
|
61 | 24 |
|
62 | 25 | def getregentry():
|
63 | 26 |
|
64 |
| - return (bz2_encode,bz2_decode,StreamReader,StreamWriter) |
| 27 | + return (encode, decode, codecs.StreamReader, codecs.StreamWriter) |
0 commit comments