PyXR

c:\python24\lib \ encodings \ bz2_codec.py



0001 """ Python 'bz2_codec' Codec - bz2 compression encoding
0002 
0003     Unlike most of the other codecs which target Unicode, this codec
0004     will return Python string objects for both encode and decode.
0005 
0006     Adapted by Raymond Hettinger from zlib_codec.py which was written
0007     by Marc-Andre Lemburg (mal@lemburg.com).
0008 
0009 """
0010 import codecs
0011 import bz2 # this codec needs the optional bz2 module !
0012 
0013 ### Codec APIs
0014 
0015 def bz2_encode(input,errors='strict'):
0016 
0017     """ Encodes the object input and returns a tuple (output
0018         object, length consumed).
0019 
0020         errors defines the error handling to apply. It defaults to
0021         'strict' handling which is the only currently supported
0022         error handling for this codec.
0023 
0024     """
0025     assert errors == 'strict'
0026     output = bz2.compress(input)
0027     return (output, len(input))
0028 
0029 def bz2_decode(input,errors='strict'):
0030 
0031     """ Decodes the object input and returns a tuple (output
0032         object, length consumed).
0033 
0034         input must be an object which provides the bf_getreadbuf
0035         buffer slot. Python strings, buffer objects and memory
0036         mapped files are examples of objects providing this slot.
0037 
0038         errors defines the error handling to apply. It defaults to
0039         'strict' handling which is the only currently supported
0040         error handling for this codec.
0041 
0042     """
0043     assert errors == 'strict'
0044     output = bz2.decompress(input)
0045     return (output, len(input))
0046 
0047 class Codec(codecs.Codec):
0048 
0049     def encode(self, input, errors='strict'):
0050         return bz2_encode(input, errors)
0051     def decode(self, input, errors='strict'):
0052         return bz2_decode(input, errors)
0053 
0054 class StreamWriter(Codec,codecs.StreamWriter):
0055     pass
0056 
0057 class StreamReader(Codec,codecs.StreamReader):
0058     pass
0059 
0060 ### encodings module API
0061 
0062 def getregentry():
0063 
0064     return (bz2_encode,bz2_decode,StreamReader,StreamWriter)
0065 

Generated by PyXR 0.9.4
SourceForge.net Logo