home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_895 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.7 KB  |  74 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. from calibre.customize.conversion import InputFormatPlugin
  9. from calibre.ebooks.conversion.utils import PreProcessor
  10.  
  11. class LITInput(InputFormatPlugin):
  12.     name = 'LIT Input'
  13.     author = 'Marshall T. Vandegrift'
  14.     description = 'Convert LIT files to HTML'
  15.     file_types = set([
  16.         'lit'])
  17.     
  18.     def convert(self, stream, options, file_ext, log, accelerators):
  19.         LitReader = LitReader
  20.         import calibre.ebooks.lit.reader
  21.         create_oebbook = create_oebbook
  22.         import calibre.ebooks.conversion.plumber
  23.         self.log = log
  24.         return create_oebbook(log, stream, options, self, reader = LitReader)
  25.  
  26.     
  27.     def postprocess_book(self, oeb, opts, log):
  28.         XHTML_NS = XHTML_NS
  29.         XPath = XPath
  30.         XHTML = XHTML
  31.         import calibre.ebooks.oeb.base
  32.         for item in oeb.spine:
  33.             root = item.data
  34.             if not hasattr(root, 'xpath'):
  35.                 continue
  36.             
  37.             for bad in ('metadata', 'guide'):
  38.                 metadata = XPath('//h:' + bad)(root)
  39.                 if metadata:
  40.                     for x in metadata:
  41.                         x.getparent().remove(x)
  42.                     
  43.             
  44.             body = XPath('//h:body')(root)
  45.             if body:
  46.                 body = body[0]
  47.                 if len(body) == 1 and body[0].tag == XHTML('pre'):
  48.                     pre = body[0]
  49.                     convert_basic = convert_basic
  50.                     import calibre.ebooks.txt.processor
  51.                     etree = etree
  52.                     import lxml
  53.                     import copy
  54.                     html = convert_basic(pre.text).replace('<html>', '<html xmlns="%s">' % XHTML_NS)
  55.                     root = etree.fromstring(html)
  56.                     body = XPath('//h:body')(root)
  57.                     pre.tag = XHTML('div')
  58.                     pre.text = ''
  59.                     for elem in body:
  60.                         ne = copy.deepcopy(elem)
  61.                         pre.append(ne)
  62.                     
  63.                 
  64.             body[0].tag == XHTML('pre')
  65.         
  66.  
  67.     
  68.     def preprocess_html(self, options, html):
  69.         self.options = options
  70.         preprocessor = PreProcessor(self.options, log = getattr(self, 'log', None))
  71.         return preprocessor(html)
  72.  
  73.  
  74.