home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_900 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.4 KB  |  66 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.  
  10. class LITInput(InputFormatPlugin):
  11.     name = 'LIT Input'
  12.     author = 'Marshall T. Vandegrift'
  13.     description = 'Convert LIT files to HTML'
  14.     file_types = set([
  15.         'lit'])
  16.     
  17.     def convert(self, stream, options, file_ext, log, accelerators):
  18.         LitReader = LitReader
  19.         import calibre.ebooks.lit.reader
  20.         create_oebbook = create_oebbook
  21.         import calibre.ebooks.conversion.plumber
  22.         return create_oebbook(log, stream, options, self, reader = LitReader)
  23.  
  24.     
  25.     def postprocess_book(self, oeb, opts, log):
  26.         XHTML_NS = XHTML_NS
  27.         XPath = XPath
  28.         XHTML = XHTML
  29.         import calibre.ebooks.oeb.base
  30.         for item in oeb.spine:
  31.             root = item.data
  32.             if not hasattr(root, 'xpath'):
  33.                 continue
  34.             
  35.             for bad in ('metadata', 'guide'):
  36.                 metadata = XPath('//h:' + bad)(root)
  37.                 if metadata:
  38.                     for x in metadata:
  39.                         x.getparent().remove(x)
  40.                     
  41.             
  42.             body = XPath('//h:body')(root)
  43.             if body:
  44.                 body = body[0]
  45.                 if len(body) == 1 and body[0].tag == XHTML('pre'):
  46.                     pre = body[0]
  47.                     convert_basic = convert_basic
  48.                     import calibre.ebooks.txt.processor
  49.                     etree = etree
  50.                     import lxml
  51.                     import copy
  52.                     html = convert_basic(pre.text).replace('<html>', '<html xmlns="%s">' % XHTML_NS)
  53.                     root = etree.fromstring(html)
  54.                     body = XPath('//h:body')(root)
  55.                     pre.tag = XHTML('div')
  56.                     pre.text = ''
  57.                     for elem in body:
  58.                         ne = copy.deepcopy(elem)
  59.                         pre.append(ne)
  60.                     
  61.                 
  62.             body[0].tag == XHTML('pre')
  63.         
  64.  
  65.  
  66.