home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_883 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  1.7 KB  |  36 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__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
  7. __docformat__ = 'restructuredtext en'
  8. from calibre.utils.zipfile import ZipFile, ZIP_STORED
  9.  
  10. def rules(stylesheets):
  11.     for s in stylesheets:
  12.         if hasattr(s, 'cssText'):
  13.             for r in s:
  14.                 if r.type == r.STYLE_RULE:
  15.                     yield r
  16.                     continue
  17.             
  18.     
  19.  
  20.  
  21. def initialize_container(path_to_container, opf_name = 'metadata.opf', extra_entries = []):
  22.     rootfiles = ''
  23.     for path, mimetype, _ in extra_entries:
  24.         rootfiles += u'<rootfile full-path="{0}" media-type="{1}"/>'.format(path, mimetype)
  25.     
  26.     CONTAINER = u'<?xml version="1.0"?>\n<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n   <rootfiles>\n      <rootfile full-path="{0}" media-type="application/oebps-package+xml"/>\n      {extra_entries}\n   </rootfiles>\n</container>\n    '.format(opf_name, extra_entries = rootfiles).encode('utf-8')
  27.     zf = ZipFile(path_to_container, 'w')
  28.     zf.writestr('mimetype', 'application/epub+zip', compression = ZIP_STORED)
  29.     zf.writestr('META-INF/', '', 448)
  30.     zf.writestr('META-INF/container.xml', CONTAINER)
  31.     for path, _, data in extra_entries:
  32.         zf.writestr(path, data)
  33.     
  34.     return zf
  35.  
  36.