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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'CSSFontFaceRule']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: cssfontfacerule.py 1868 2009-10-17 19:36:54Z cthedot $'
  8. from cssstyledeclaration import CSSStyleDeclaration
  9. import cssrule
  10. import cssutils
  11. import xml.dom as xml
  12.  
  13. class CSSFontFaceRule(cssrule.CSSRule):
  14.     
  15.     def __init__(self, style = None, parentRule = None, parentStyleSheet = None, readonly = False):
  16.         super(CSSFontFaceRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
  17.         self._atkeyword = u'@font-face'
  18.         self._style = CSSStyleDeclaration(parentRule = self)
  19.         if style:
  20.             self.style = style
  21.         
  22.         self._readonly = readonly
  23.  
  24.     
  25.     def __repr__(self):
  26.         return 'cssutils.css.%s(style=%r)' % (self.__class__.__name__, self.style.cssText)
  27.  
  28.     
  29.     def __str__(self):
  30.         return '<cssutils.css.%s object style=%r valid=%r at 0x%x>' % (self.__class__.__name__, self.style.cssText, self.valid, id(self))
  31.  
  32.     
  33.     def _getCssText(self):
  34.         return cssutils.ser.do_CSSFontFaceRule(self)
  35.  
  36.     
  37.     def _setCssText(self, cssText):
  38.         super(CSSFontFaceRule, self)._setCssText(cssText)
  39.         tokenizer = self._tokenize2(cssText)
  40.         attoken = self._nexttoken(tokenizer, None)
  41.         if self._type(attoken) != self._prods.FONT_FACE_SYM:
  42.             self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' % self._valuestr(cssText), error = xml.dom.InvalidModificationErr)
  43.         else:
  44.             oldstyle = CSSStyleDeclaration()
  45.             oldstyle._absorb(self.style)
  46.             ok = True
  47.             (beforetokens, brace) = self._tokensupto2(tokenizer, blockstartonly = True, separateEnd = True)
  48.             if self._tokenvalue(brace) != u'{':
  49.                 ok = False
  50.                 self._log.error(u'CSSFontFaceRule: No start { of style declaration found: %r' % self._valuestr(cssText), brace)
  51.             
  52.             new = {
  53.                 'wellformed': True }
  54.             newseq = self._tempSeq()
  55.             (beforewellformed, expected) = self._parse(expected = ':', seq = newseq, tokenizer = self._tokenize2(beforetokens), productions = { })
  56.             if ok and beforewellformed:
  57.                 pass
  58.             ok = new['wellformed']
  59.             (styletokens, braceorEOFtoken) = self._tokensupto2(tokenizer, blockendonly = True, separateEnd = True)
  60.             val = self._tokenvalue(braceorEOFtoken)
  61.             typ = self._type(braceorEOFtoken)
  62.             if val != u'}' and typ != 'EOF':
  63.                 ok = False
  64.                 self._log.error(u'CSSFontFaceRule: No "}" after style declaration found: %r' % self._valuestr(cssText))
  65.             
  66.             nonetoken = self._nexttoken(tokenizer)
  67.             if nonetoken:
  68.                 ok = False
  69.                 self._log.error(u'CSSFontFaceRule: Trailing content found.', token = nonetoken)
  70.             
  71.             if 'EOF' == typ:
  72.                 styletokens.append(braceorEOFtoken)
  73.             
  74.             self.style.cssText = styletokens
  75.             if ok:
  76.                 self._setSeq(newseq)
  77.             else:
  78.                 self.style._absorb(oldstyle)
  79.  
  80.     cssText = property(_getCssText, _setCssText, doc = '(DOM) The parsable textual representation of this rule.')
  81.     
  82.     def _setStyle(self, style):
  83.         self._checkReadonly()
  84.         if isinstance(style, basestring):
  85.             self._style.cssText = style
  86.         else:
  87.             self._style = style
  88.             self._style.parentRule = self
  89.  
  90.     style = property((lambda self: self._style), _setStyle, doc = '(DOM) The declaration-block of this rule set, a :class:`~cssutils.css.CSSStyleDeclaration`.')
  91.     type = property((lambda self: self.FONT_FACE_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
  92.     
  93.     def _getValid(self):
  94.         needed = [
  95.             'font-family',
  96.             'src']
  97.         for p in self.style.getProperties(all = True):
  98.             if not p.valid:
  99.                 return False
  100.             
  101.             try:
  102.                 needed.remove(p.name)
  103.             continue
  104.             except ValueError:
  105.                 p.valid
  106.                 p.valid
  107.                 continue
  108.             
  109.  
  110.         
  111.         return not bool(needed)
  112.  
  113.     valid = property(_getValid, doc = 'CSSFontFace is valid if properties `font-family` and `src` are set and all properties are valid.')
  114.     wellformed = property((lambda self: True))
  115.  
  116.