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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2009, John Schember <john@nachtimwald.com>'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. import struct
  9. from calibre.ebooks.pdb.formatreader import FormatReader
  10. from calibre.ebooks.txt.processor import convert_basic, opf_writer, separate_paragraphs_single_line, separate_paragraphs_print_formatted
  11.  
  12. class HeaderRecord(object):
  13.     
  14.     def __init__(self, raw):
  15.         (self.compression,) = struct.unpack('>H', raw[0:2])
  16.         (self.num_records,) = struct.unpack('>H', raw[8:10])
  17.  
  18.  
  19.  
  20. class Reader(FormatReader):
  21.     
  22.     def __init__(self, header, stream, log, options):
  23.         self.stream = stream
  24.         self.log = log
  25.         self.encoding = options.input_encoding
  26.         self.single_line_paras = options.single_line_paras
  27.         self.print_formatted_paras = options.print_formatted_paras
  28.         self.sections = []
  29.         for i in range(header.num_sections):
  30.             self.sections.append(header.section_data(i))
  31.         
  32.         self.header_record = HeaderRecord(self.section_data(0))
  33.  
  34.     
  35.     def section_data(self, number):
  36.         return self.sections[number]
  37.  
  38.     
  39.     def decompress_text(self, number):
  40.         if self.header_record.compression == 1:
  41.             return None(self.section_data(number).decode if self.encoding is None else self.encoding)
  42.         if self.header_record.compression == 2 or self.header_record.compression == 258:
  43.             decompress_doc = decompress_doc
  44.             import calibre.ebooks.compression.palmdoc
  45.             return self.header_record.compression == 1(decompress_doc(self.section_data(number)).decode if self.encoding is None else self.encoding, 'replace')
  46.         return ''
  47.  
  48.     
  49.     def extract_content(self, output_dir):
  50.         txt = ''
  51.         self.log.info('Decompressing text...')
  52.         for i in range(1, self.header_record.num_records + 1):
  53.             self.log.debug('\tDecompressing text section %i' % i)
  54.             txt += self.decompress_text(i)
  55.         
  56.         self.log.info('Converting text to OEB...')
  57.         if self.single_line_paras:
  58.             txt = separate_paragraphs_single_line(txt)
  59.         
  60.         if self.print_formatted_paras:
  61.             txt = separate_paragraphs_print_formatted(txt)
  62.         
  63.         html = convert_basic(txt)
  64.         
  65.         try:
  66.             index = _[1]
  67.             index.write(html.encode('utf-8'))
  68.         finally:
  69.             pass
  70.  
  71.         get_metadata = get_metadata
  72.         import calibre.ebooks.metadata.meta
  73.         mi = get_metadata(self.stream, 'pdb')
  74.         manifest = [
  75.             ('index.html', None)]
  76.         spine = [
  77.             'index.html']
  78.         opf_writer(output_dir, 'metadata.opf', manifest, spine, mi)
  79.         return os.path.join(output_dir, 'metadata.opf')
  80.  
  81.  
  82.