home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1522 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  6.9 KB  |  169 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'CSSUnknownRule']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: cssunknownrule.py 1897 2009-12-17 22:09:06Z cthedot $'
  8. import cssrule
  9. import cssutils
  10. import xml.dom as xml
  11.  
  12. class CSSUnknownRule(cssrule.CSSRule):
  13.     
  14.     def __init__(self, cssText = u'', parentRule = None, parentStyleSheet = None, readonly = False):
  15.         super(CSSUnknownRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
  16.         self._atkeyword = None
  17.         if cssText:
  18.             self.cssText = cssText
  19.         
  20.         self._readonly = readonly
  21.  
  22.     
  23.     def __repr__(self):
  24.         return 'cssutils.css.%s(cssText=%r)' % (self.__class__.__name__, self.cssText)
  25.  
  26.     
  27.     def __str__(self):
  28.         return '<cssutils.css.%s object cssText=%r at 0x%x>' % (self.__class__.__name__, self.cssText, id(self))
  29.  
  30.     
  31.     def _getCssText(self):
  32.         return cssutils.ser.do_CSSUnknownRule(self)
  33.  
  34.     
  35.     def _setCssText(self, cssText):
  36.         super(CSSUnknownRule, self)._setCssText(cssText)
  37.         tokenizer = self._tokenize2(cssText)
  38.         attoken = self._nexttoken(tokenizer, None)
  39.         if not attoken or self._type(attoken) != self._prods.ATKEYWORD:
  40.             self._log.error(u'CSSUnknownRule: No CSSUnknownRule found: %s' % self._valuestr(cssText), error = xml.dom.InvalidModificationErr)
  41.         else:
  42.             new = {
  43.                 'nesting': [],
  44.                 'wellformed': True }
  45.             
  46.             def CHAR(expected, seq, token, tokenizer = (None, None)):
  47.                 (type_, val, line, col) = token
  48.                 if expected != 'EOF':
  49.                     if val in u'{[(':
  50.                         new['nesting'].append(val)
  51.                     elif val in u'}])':
  52.                         opening = {
  53.                             u'}': u'{',
  54.                             u']': u'[',
  55.                             u')': u'(' }[val]
  56.                         
  57.                         try:
  58.                             if new['nesting'][-1] == opening:
  59.                                 new['nesting'].pop()
  60.                             else:
  61.                                 raise IndexError()
  62.                         except IndexError:
  63.                             new['wellformed'] = False
  64.                             self._log.error(u'CSSUnknownRule: Wrong nesting of {, [ or (.', token = token)
  65.                         except:
  66.                             None<EXCEPTION MATCH>IndexError
  67.                         
  68.  
  69.                     None<EXCEPTION MATCH>IndexError
  70.                     if val in u'};' and not new['nesting']:
  71.                         expected = 'EOF'
  72.                     
  73.                     seq.append(val, type_, line = line, col = col)
  74.                     return expected
  75.                 new['wellformed'] = False
  76.                 self._log.error(u'CSSUnknownRule: Expected end of rule.', token = token)
  77.                 return expected
  78.  
  79.             
  80.             def FUNCTION(expected, seq, token, tokenizer = (None, None)):
  81.                 (type_, val, line, col) = token
  82.                 val = self._tokenvalue(token)
  83.                 if expected != 'EOF':
  84.                     new['nesting'].append(u'(')
  85.                     seq.append(val, type_, line = line, col = col)
  86.                     return expected
  87.                 new['wellformed'] = False
  88.                 self._log.error(u'CSSUnknownRule: Expected end of rule.', token = token)
  89.                 return expected
  90.  
  91.             
  92.             def EOF(expected, seq, token, tokenizer = (None,)):
  93.                 for x in reversed(new['nesting']):
  94.                     closing = {
  95.                         u'{': u'}',
  96.                         u'[': u']',
  97.                         u'(': u')' }[x]
  98.                     seq.append(closing, closing)
  99.                 
  100.                 new['nesting'] = []
  101.                 return 'EOF'
  102.  
  103.             
  104.             def INVALID(expected, seq, token, tokenizer = (None, None)):
  105.                 self._log.error(u'CSSUnknownRule: Bad syntax.', token = token, error = xml.dom.SyntaxErr)
  106.                 new['wellformed'] = False
  107.                 return expected
  108.  
  109.             
  110.             def STRING(expected, seq, token, tokenizer = (None, None)):
  111.                 (type_, val, line, col) = token
  112.                 val = self._stringtokenvalue(token)
  113.                 if expected != 'EOF':
  114.                     seq.append(val, type_, line = line, col = col)
  115.                     return expected
  116.                 new['wellformed'] = False
  117.                 self._log.error(u'CSSUnknownRule: Expected end of rule.', token = token)
  118.                 return expected
  119.  
  120.             
  121.             def URI(expected, seq, token, tokenizer = (None, None)):
  122.                 (type_, val, line, col) = token
  123.                 val = self._uritokenvalue(token)
  124.                 if expected != 'EOF':
  125.                     seq.append(val, type_, line = line, col = col)
  126.                     return expected
  127.                 new['wellformed'] = False
  128.                 self._log.error(u'CSSUnknownRule: Expected end of rule.', token = token)
  129.                 return expected
  130.  
  131.             
  132.             def default(expected, seq, token, tokenizer = (None, None)):
  133.                 (type_, val, line, col) = token
  134.                 if expected != 'EOF':
  135.                     seq.append(val, type_, line = line, col = col)
  136.                     return expected
  137.                 new['wellformed'] = False
  138.                 self._log.error(u'CSSUnknownRule: Expected end of rule.', token = token)
  139.                 return expected
  140.  
  141.             newseq = self._tempSeq()
  142.             (wellformed, expected) = self._parse(expected = None, seq = newseq, tokenizer = tokenizer, productions = {
  143.                 'CHAR': CHAR,
  144.                 'EOF': EOF,
  145.                 'FUNCTION': FUNCTION,
  146.                 'INVALID': INVALID,
  147.                 'STRING': STRING,
  148.                 'URI': URI,
  149.                 'S': default }, default = default, new = new)
  150.             if wellformed:
  151.                 pass
  152.             wellformed = new['wellformed']
  153.             if expected != 'EOF':
  154.                 wellformed = False
  155.                 self._log.error(u'CSSUnknownRule: No ending ";" or "}" found: %r' % self._valuestr(cssText))
  156.             elif new['nesting']:
  157.                 wellformed = False
  158.                 self._log.error(u'CSSUnknownRule: Unclosed "{", "[" or "(": %r' % self._valuestr(cssText))
  159.             
  160.             if wellformed:
  161.                 self.atkeyword = self._tokenvalue(attoken)
  162.                 self._setSeq(newseq)
  163.             
  164.  
  165.     cssText = property(fget = _getCssText, fset = _setCssText, doc = '(DOM) The parsable textual representation.')
  166.     type = property((lambda self: self.UNKNOWN_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
  167.     wellformed = property((lambda self: bool(self.atkeyword)))
  168.  
  169.