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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from xml.sax import make_parser, handler
  5. from xml.sax.xmlreader import InputSource
  6. import xml.sax.saxutils as xml
  7. from element import Element
  8. from namespaces import OFFICENS
  9. from cStringIO import StringIO
  10.  
  11. class LoadParser(handler.ContentHandler):
  12.     triggers = ((OFFICENS, 'automatic-styles'), (OFFICENS, 'body'), (OFFICENS, 'font-face-decls'), (OFFICENS, 'master-styles'), (OFFICENS, 'meta'), (OFFICENS, 'scripts'), (OFFICENS, 'settings'), (OFFICENS, 'styles'))
  13.     
  14.     def __init__(self, document):
  15.         self.doc = document
  16.         self.data = []
  17.         self.level = 0
  18.         self.parse = False
  19.  
  20.     
  21.     def characters(self, data):
  22.         if self.parse == False:
  23.             return None
  24.         self.data.append(data)
  25.  
  26.     
  27.     def startElementNS(self, tag, qname, attrs):
  28.         if tag in self.triggers:
  29.             self.parse = True
  30.         
  31.         if self.doc._parsing != 'styles.xml' and tag == (OFFICENS, 'font-face-decls'):
  32.             self.parse = False
  33.         
  34.         if self.parse == False:
  35.             return None
  36.         self.level = self.level + 1
  37.         content = ''.join(self.data).strip()
  38.         if len(content) > 0:
  39.             self.parent.addText(content, check_grammar = False)
  40.             self.data = []
  41.         
  42.         attrdict = { }
  43.         for att, value in attrs.items():
  44.             attrdict[att] = value
  45.         
  46.         
  47.         try:
  48.             e = Element(qname = tag, qattributes = attrdict, check_grammar = False)
  49.             self.curr = e
  50.         except AttributeError:
  51.             v = None
  52.             print 'Error: %s' % v
  53.  
  54.         if tag == (OFFICENS, 'automatic-styles'):
  55.             e = self.doc.automaticstyles
  56.         elif tag == (OFFICENS, 'body'):
  57.             e = self.doc.body
  58.         elif tag == (OFFICENS, 'master-styles'):
  59.             e = self.doc.masterstyles
  60.         elif tag == (OFFICENS, 'meta'):
  61.             e = self.doc.meta
  62.         elif tag == (OFFICENS, 'scripts'):
  63.             e = self.doc.scripts
  64.         elif tag == (OFFICENS, 'settings'):
  65.             e = self.doc.settings
  66.         elif tag == (OFFICENS, 'styles'):
  67.             e = self.doc.styles
  68.         elif self.doc._parsing == 'styles.xml' and tag == (OFFICENS, 'font-face-decls'):
  69.             e = self.doc.fontfacedecls
  70.         elif hasattr(self, 'parent'):
  71.             self.parent.addElement(e, check_grammar = False)
  72.         
  73.         self.parent = e
  74.  
  75.     
  76.     def endElementNS(self, tag, qname):
  77.         if self.parse == False:
  78.             return None
  79.         self.level = self.level - 1
  80.         str = ''.join(self.data)
  81.         if len(str.strip()) > 0:
  82.             self.curr.addText(str, check_grammar = False)
  83.         
  84.         self.data = []
  85.         self.curr = self.curr.parentNode
  86.         self.parent = self.curr
  87.         if tag in self.triggers:
  88.             self.parse = False
  89.         
  90.  
  91.  
  92.