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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'CSSStyleRule']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: cssstylerule.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 CSSStyleRule(cssrule.CSSRule):
  15.     
  16.     def __init__(self, selectorText = None, style = None, parentRule = None, parentStyleSheet = None, readonly = False):
  17.         super(CSSStyleRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
  18.         self._selectorList = SelectorList(parentRule = self)
  19.         self._style = CSSStyleDeclaration(parentRule = self)
  20.         if selectorText:
  21.             self.selectorText = selectorText
  22.         
  23.         if style:
  24.             self.style = style
  25.         
  26.         self._readonly = readonly
  27.  
  28.     
  29.     def __repr__(self):
  30.         if self._namespaces:
  31.             st = (self.selectorText, self._namespaces)
  32.         else:
  33.             st = self.selectorText
  34.         return 'cssutils.css.%s(selectorText=%r, style=%r)' % (self.__class__.__name__, st, self.style.cssText)
  35.  
  36.     
  37.     def __str__(self):
  38.         return '<cssutils.css.%s object selector=%r style=%r _namespaces=%r at 0x%x>' % (self.__class__.__name__, self.selectorText, self.style.cssText, self._namespaces, id(self))
  39.  
  40.     
  41.     def _getCssText(self):
  42.         return cssutils.ser.do_CSSStyleRule(self)
  43.  
  44.     
  45.     def _setCssText(self, cssText):
  46.         super(CSSStyleRule, self)._setCssText(cssText)
  47.         (cssText, namespaces) = self._splitNamespacesOff(cssText)
  48.         
  49.         try:
  50.             namespaces = self.parentStyleSheet.namespaces
  51.         except AttributeError:
  52.             pass
  53.  
  54.         tokenizer = self._tokenize2(cssText)
  55.         selectortokens = self._tokensupto2(tokenizer, blockstartonly = True)
  56.         styletokens = self._tokensupto2(tokenizer, blockendonly = True)
  57.         trail = self._nexttoken(tokenizer)
  58.         if trail:
  59.             self._log.error(u'CSSStyleRule: Trailing content: %s' % self._valuestr(cssText), token = trail)
  60.         elif not selectortokens:
  61.             self._log.error(u'CSSStyleRule: No selector found: %r' % self._valuestr(cssText))
  62.         elif self._tokenvalue(selectortokens[0]).startswith(u'@'):
  63.             self._log.error(u'CSSStyleRule: No style rule: %r' % self._valuestr(cssText), error = xml.dom.InvalidModificationErr)
  64.         else:
  65.             oldstyle = CSSStyleDeclaration()
  66.             oldstyle._absorb(self.style)
  67.             oldselector = SelectorList()
  68.             oldselector._absorb(self.selectorList)
  69.             ok = True
  70.             bracetoken = selectortokens.pop()
  71.             if self._tokenvalue(bracetoken) != u'{':
  72.                 ok = False
  73.                 self._log.error(u'CSSStyleRule: No start { of style declaration found: %r' % self._valuestr(cssText), bracetoken)
  74.             elif not selectortokens:
  75.                 ok = False
  76.                 self._log.error(u'CSSStyleRule: No selector found: %r.' % self._valuestr(cssText), bracetoken)
  77.             
  78.             self.selectorList.selectorText = (selectortokens, namespaces)
  79.             if not styletokens:
  80.                 ok = False
  81.                 self._log.error(u'CSSStyleRule: No style declaration or "}" found: %r' % self._valuestr(cssText))
  82.             else:
  83.                 braceorEOFtoken = styletokens.pop()
  84.                 val = self._tokenvalue(braceorEOFtoken)
  85.                 typ = self._type(braceorEOFtoken)
  86.                 if val != u'}' and typ != 'EOF':
  87.                     ok = False
  88.                     self._log.error(u'CSSStyleRule: No "}" after style declaration found: %r' % self._valuestr(cssText))
  89.                 elif 'EOF' == typ:
  90.                     styletokens.append(braceorEOFtoken)
  91.                 
  92.                 
  93.                 try:
  94.                     self.style.cssText = styletokens
  95.                 except:
  96.                     self.selectorList._absorb(oldselector)
  97.                     raise 
  98.  
  99.             if not ok or not (self.wellformed):
  100.                 self.selectorList._absorb(oldselector)
  101.                 self.style._absorb(oldstyle)
  102.             
  103.  
  104.     cssText = property(_getCssText, _setCssText, doc = '(DOM) The parsable textual representation of this rule.')
  105.     
  106.     def __getNamespaces(self):
  107.         
  108.         try:
  109.             return self.parentStyleSheet.namespaces
  110.         except AttributeError:
  111.             return self.selectorList._namespaces
  112.  
  113.  
  114.     _namespaces = property(__getNamespaces, doc = 'If this Rule is attached to a CSSStyleSheet the namespaces of that sheet are mirrored here. While the Rule is not attached the namespaces of selectorList are used.')
  115.     
  116.     def _setSelectorList(self, selectorList):
  117.         self._checkReadonly()
  118.         selectorList._parentRule = self
  119.         self._selectorList = selectorList
  120.  
  121.     selectorList = property((lambda self: self._selectorList), _setSelectorList, doc = 'The SelectorList of this rule.')
  122.     
  123.     def _setSelectorText(self, selectorText):
  124.         self._checkReadonly()
  125.         self._selectorList.selectorText = selectorText
  126.  
  127.     selectorText = property((lambda self: self._selectorList.selectorText), _setSelectorText, doc = '(DOM) The textual representation of the selector for the rule set.')
  128.     
  129.     def _setStyle(self, style):
  130.         self._checkReadonly()
  131.         if isinstance(style, basestring):
  132.             self._style.cssText = style
  133.         else:
  134.             style._parentRule = self
  135.             self._style = style
  136.  
  137.     style = property((lambda self: self._style), _setStyle, doc = '(DOM) The declaration-block of this rule set.')
  138.     type = property((lambda self: self.STYLE_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
  139.     wellformed = property((lambda self: self.selectorList.wellformed))
  140.  
  141.