home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_461 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.1 KB  |  79 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import codecs
  5. import bz2
  6.  
  7. def bz2_encode(input, errors = 'strict'):
  8.     output = bz2.compress(input)
  9.     return (output, len(input))
  10.  
  11.  
  12. def bz2_decode(input, errors = 'strict'):
  13.     output = bz2.decompress(input)
  14.     return (output, len(input))
  15.  
  16.  
  17. class Codec(codecs.Codec):
  18.     
  19.     def encode(self, input, errors = 'strict'):
  20.         return bz2_encode(input, errors)
  21.  
  22.     
  23.     def decode(self, input, errors = 'strict'):
  24.         return bz2_decode(input, errors)
  25.  
  26.  
  27.  
  28. class IncrementalEncoder(codecs.IncrementalEncoder):
  29.     
  30.     def __init__(self, errors = 'strict'):
  31.         self.errors = errors
  32.         self.compressobj = bz2.BZ2Compressor()
  33.  
  34.     
  35.     def encode(self, input, final = False):
  36.         if final:
  37.             c = self.compressobj.compress(input)
  38.             return c + self.compressobj.flush()
  39.         return self.compressobj.compress(input)
  40.  
  41.     
  42.     def reset(self):
  43.         self.compressobj = bz2.BZ2Compressor()
  44.  
  45.  
  46.  
  47. class IncrementalDecoder(codecs.IncrementalDecoder):
  48.     
  49.     def __init__(self, errors = 'strict'):
  50.         self.errors = errors
  51.         self.decompressobj = bz2.BZ2Decompressor()
  52.  
  53.     
  54.     def decode(self, input, final = False):
  55.         
  56.         try:
  57.             return self.decompressobj.decompress(input)
  58.         except EOFError:
  59.             return ''
  60.  
  61.  
  62.     
  63.     def reset(self):
  64.         self.decompressobj = bz2.BZ2Decompressor()
  65.  
  66.  
  67.  
  68. class StreamWriter(Codec, codecs.StreamWriter):
  69.     pass
  70.  
  71.  
  72. class StreamReader(Codec, codecs.StreamReader):
  73.     pass
  74.  
  75.  
  76. def getregentry():
  77.     return codecs.CodecInfo(name = 'bz2', encode = bz2_encode, decode = bz2_decode, incrementalencoder = IncrementalEncoder, incrementaldecoder = IncrementalDecoder, streamwriter = StreamWriter, streamreader = StreamReader)
  78.  
  79.