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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'CSSPageRule']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: csspagerule.py 1868 2009-10-17 19:36:54Z cthedot $'
  8. from cssstyledeclaration import CSSStyleDeclaration
  9. from selectorlist import SelectorList
  10. import cssrule
  11. import cssutils
  12. import xml.dom as xml
  13.  
  14. class CSSPageRule(cssrule.CSSRule):
  15.     
  16.     def __init__(self, selectorText = None, style = None, parentRule = None, parentStyleSheet = None, readonly = False):
  17.         super(CSSPageRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
  18.         self._atkeyword = u'@page'
  19.         tempseq = self._tempSeq()
  20.         if selectorText:
  21.             self.selectorText = selectorText
  22.             tempseq.append(self.selectorText, 'selectorText')
  23.         else:
  24.             self._selectorText = self._tempSeq()
  25.         self._style = CSSStyleDeclaration(parentRule = self)
  26.         if style:
  27.             self.style = style
  28.             tempseq.append(self.style, 'style')
  29.         
  30.         self._setSeq(tempseq)
  31.         self._readonly = readonly
  32.  
  33.     
  34.     def __repr__(self):
  35.         return 'cssutils.css.%s(selectorText=%r, style=%r)' % (self.__class__.__name__, self.selectorText, self.style.cssText)
  36.  
  37.     
  38.     def __str__(self):
  39.         return '<cssutils.css.%s object selectorText=%r style=%r at 0x%x>' % (self.__class__.__name__, self.selectorText, self.style.cssText, id(self))
  40.  
  41.     
  42.     def __parseSelectorText(self, selectorText):
  43.         new = {
  44.             'wellformed': True,
  45.             'last-S': False }
  46.         
  47.         def _char(expected, seq, token, tokenizer = (None, None)):
  48.             val = self._tokenvalue(token)
  49.             if not new['last-S'] and expected in ('page', ': or EOF') and u':' == val:
  50.                 
  51.                 try:
  52.                     identtoken = tokenizer.next()
  53.                 except StopIteration:
  54.                     self._log.error(u'CSSPageRule selectorText: No IDENT found.', token)
  55.  
  56.                 ival = self._tokenvalue(identtoken)
  57.                 ityp = self._type(identtoken)
  58.                 if self._prods.IDENT != ityp:
  59.                     self._log.error(u'CSSPageRule selectorText: Expected IDENT but found: %r' % ival, token)
  60.                 else:
  61.                     seq.append(val + ival, 'pseudo')
  62.                     return 'EOF'
  63.                 return self._prods.IDENT != ityp
  64.             new['wellformed'] = False
  65.             self._log.error(u'CSSPageRule selectorText: Unexpected CHAR: %r' % val, token)
  66.             return expected
  67.  
  68.         
  69.         def S(expected, seq, token, tokenizer = (None,)):
  70.             if expected == ': or EOF':
  71.                 new['last-S'] = True
  72.             
  73.             return expected
  74.  
  75.         
  76.         def IDENT(expected, seq, token, tokenizer = (None, None)):
  77.             val = self._tokenvalue(token)
  78.             if 'page' == expected:
  79.                 seq.append(val, 'IDENT')
  80.                 return ': or EOF'
  81.             new['wellformed'] = False
  82.             self._log.error(u'CSSPageRule selectorText: Unexpected IDENT: %r' % val, token)
  83.             return expected
  84.  
  85.         
  86.         def COMMENT(expected, seq, token, tokenizer = None):
  87.             seq.append(cssutils.css.CSSComment([
  88.                 token]), 'COMMENT')
  89.             return expected
  90.  
  91.         newseq = self._tempSeq()
  92.         (wellformed, expected) = self._parse(expected = 'page', seq = newseq, tokenizer = self._tokenize2(selectorText), productions = {
  93.             'CHAR': _char,
  94.             'IDENT': IDENT,
  95.             'COMMENT': COMMENT,
  96.             'S': S }, new = new)
  97.         if wellformed:
  98.             pass
  99.         wellformed = new['wellformed']
  100.         if expected == 'ident':
  101.             self._log.error(u'CSSPageRule selectorText: No valid selector: %r' % self._valuestr(selectorText))
  102.         
  103.         return (wellformed, newseq)
  104.  
  105.     
  106.     def _getCssText(self):
  107.         return cssutils.ser.do_CSSPageRule(self)
  108.  
  109.     
  110.     def _setCssText(self, cssText):
  111.         super(CSSPageRule, self)._setCssText(cssText)
  112.         tokenizer = self._tokenize2(cssText)
  113.         if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:
  114.             self._log.error(u'CSSPageRule: No CSSPageRule found: %s' % self._valuestr(cssText), error = xml.dom.InvalidModificationErr)
  115.         else:
  116.             oldstyle = CSSStyleDeclaration()
  117.             oldstyle._absorb(self.style)
  118.             ok = True
  119.             (selectortokens, startbrace) = self._tokensupto2(tokenizer, blockstartonly = True, separateEnd = True)
  120.             (styletokens, braceorEOFtoken) = self._tokensupto2(tokenizer, blockendonly = True, separateEnd = True)
  121.             nonetoken = self._nexttoken(tokenizer)
  122.             if self._tokenvalue(startbrace) != u'{':
  123.                 ok = False
  124.                 self._log.error(u'CSSPageRule: No start { of style declaration found: %r' % self._valuestr(cssText), startbrace)
  125.             elif nonetoken:
  126.                 ok = False
  127.                 self._log.error(u'CSSPageRule: Trailing content found.', token = nonetoken)
  128.             
  129.             (selok, newselectorseq) = self._CSSPageRule__parseSelectorText(selectortokens)
  130.             if ok:
  131.                 pass
  132.             ok = selok
  133.             val = self._tokenvalue(braceorEOFtoken)
  134.             typ = self._type(braceorEOFtoken)
  135.             if val != u'}' and typ != 'EOF':
  136.                 ok = False
  137.                 self._log.error(u'CSSPageRule: No "}" after style declaration found: %r' % self._valuestr(cssText))
  138.             elif 'EOF' == typ:
  139.                 styletokens.append(braceorEOFtoken)
  140.             
  141.             self.style.cssText = styletokens
  142.             if ok:
  143.                 self._selectorText = newselectorseq
  144.             else:
  145.                 self.style._absorb(oldstyle)
  146.  
  147.     cssText = property(_getCssText, _setCssText, doc = '(DOM) The parsable textual representation of this rule.')
  148.     
  149.     def _getSelectorText(self):
  150.         return cssutils.ser.do_CSSPageRuleSelector(self._selectorText)
  151.  
  152.     
  153.     def _setSelectorText(self, selectorText):
  154.         self._checkReadonly()
  155.         (wellformed, newseq) = self._CSSPageRule__parseSelectorText(selectorText)
  156.         if wellformed:
  157.             self._selectorText = newseq
  158.         
  159.  
  160.     selectorText = property(_getSelectorText, _setSelectorText, doc = '(DOM) The parsable textual representation of the page selector for the rule.')
  161.     
  162.     def _setStyle(self, style):
  163.         self._checkReadonly()
  164.         if isinstance(style, basestring):
  165.             self._style.cssText = style
  166.         else:
  167.             self._style = style
  168.             self._style.parentRule = self
  169.  
  170.     style = property((lambda self: self._style), _setStyle, doc = '(DOM) The declaration-block of this rule set, a :class:`~cssutils.css.CSSStyleDeclaration`.')
  171.     type = property((lambda self: self.PAGE_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
  172.     wellformed = property((lambda self: True))
  173.  
  174.