PyXR

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



0001 """ Python 'zlib_codec' Codec - zlib 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     Written by Marc-Andre Lemburg (mal@lemburg.com).
0007 
0008 """
0009 import codecs
0010 import zlib # this codec needs the optional zlib module !
0011 
0012 ### Codec APIs
0013 
0014 def zlib_encode(input,errors='strict'):
0015 
0016     """ Encodes the object input and returns a tuple (output
0017         object, length consumed).
0018 
0019         errors defines the error handling to apply. It defaults to
0020         'strict' handling which is the only currently supported
0021         error handling for this codec.
0022 
0023     """
0024     assert errors == 'strict'
0025     output = zlib.compress(input)
0026     return (output, len(input))
0027 
0028 def zlib_decode(input,errors='strict'):
0029 
0030     """ Decodes the object input and returns a tuple (output
0031         object, length consumed).
0032 
0033         input must be an object which provides the bf_getreadbuf
0034         buffer slot. Python strings, buffer objects and memory
0035         mapped files are examples of objects providing this slot.
0036 
0037         errors defines the error handling to apply. It defaults to
0038         'strict' handling which is the only currently supported
0039         error handling for this codec.
0040 
0041     """
0042     assert errors == 'strict'
0043     output = zlib.decompress(input)
0044     return (output, len(input))
0045 
0046 class Codec(codecs.Codec):
0047 
0048     def encode(self, input, errors='strict'):
0049         return zlib_encode(input, errors)
0050     def decode(self, input, errors='strict'):
0051         return zlib_decode(input, errors)
0052 
0053 class StreamWriter(Codec,codecs.StreamWriter):
0054     pass
0055 
0056 class StreamReader(Codec,codecs.StreamReader):
0057     pass
0058 
0059 ### encodings module API
0060 
0061 def getregentry():
0062 
0063     return (zlib_encode,zlib_decode,StreamReader,StreamWriter)
0064 

Generated by PyXR 0.9.4
SourceForge.net Logo