home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_896 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.2 KB  |  26 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. import re
  9. from lxml.etree import tostring as _tostring
  10.  
  11. def tostring(root, strip_comments = False, pretty_print = False):
  12.     root.set('xmlns', 'http://www.w3.org/1999/xhtml')
  13.     root.set('{http://www.w3.org/1999/xhtml}xlink', 'http://www.w3.org/1999/xlink')
  14.     for x in root.iter():
  15.         if hasattr(x.tag, 'rpartition') and x.tag.rpartition('}')[-1].lower() == 'svg':
  16.             x.set('xmlns', 'http://www.w3.org/2000/svg')
  17.             continue
  18.     
  19.     ans = _tostring(root, encoding = 'utf-8', pretty_print = pretty_print)
  20.     if strip_comments:
  21.         ans = re.compile('<!--.*?-->', re.DOTALL).sub('', ans)
  22.     
  23.     ans = '<?xml version="1.0" encoding="utf-8" ?>\n' + ans
  24.     return ans
  25.  
  26.