Package cssutils :: Package css :: Module cssunknownrule
[hide private]
[frames] | no frames]

Source Code for Module cssutils.css.cssunknownrule

  1  """CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule. 
  2  """ 
  3  __all__ = ['CSSUnknownRule'] 
  4  __docformat__ = 'restructuredtext' 
  5  __author__ = '$LastChangedBy: doerwalter $' 
  6  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $' 
  7  __version__ = '0.9.2a5, $LastChangedRevision: 160 $' 
  8   
  9  import xml.dom 
 10   
 11  import cssrule 
 12  import cssutils 
 13   
 14   
15 -class CSSUnknownRule(cssrule.CSSRule):
16 """ 17 represents an at-rule not supported by this user agent. 18 19 Properties 20 ========== 21 atkeyword 22 keyword used including @, e.g. @-moz-unknown 23 cssText: of type DOMString 24 The parsable textual representation of this rule 25 seq: a list (cssutils) 26 All parts of this rule excluding @KEYWORD but including CSSComments 27 type: see CSSRule 28 The typecode for this rule 29 30 cssutils only 31 ------------- 32 atkeyword: 33 the literal keyword used 34 35 Inherits properties from CSSRule 36 37 Format 38 ====== 39 unknownrule: 40 @xxx until ';' or block {...} 41 """ 42 type = cssrule.CSSRule.UNKNOWN_RULE 43
44 - def __init__(self, cssText=u'', readonly=False):
45 """ 46 cssText 47 of type string 48 """ 49 super(CSSUnknownRule, self).__init__() 50 51 if cssText: 52 self.cssText = cssText 53 else: 54 self.atkeyword = None 55 56 self._readonly = readonly
57 58
59 - def _getCssText(self):
60 """ returns serialized property cssText """ 61 return cssutils.ser.do_CSSUnknownRule(self)
62
63 - def _setCssText(self, cssText):
64 """ 65 DOMException on setting 66 67 - SYNTAX_ERR: 68 Raised if the specified CSS string value has a syntax error and 69 is unparsable. 70 - INVALID_MODIFICATION_ERR: 71 Raised if the specified CSS string value represents a different 72 type of rule than the current one. 73 - HIERARCHY_REQUEST_ERR: (never raised) 74 Raised if the rule cannot be inserted at this point in the 75 style sheet. 76 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule) 77 Raised if the rule is readonly. 78 """ 79 super(CSSUnknownRule, self)._setCssText(cssText) 80 tokens = self._tokenize(cssText) 81 82 if not tokens or tokens and tokens[0].type != self._ttypes.ATKEYWORD: 83 self._log.error(u'CSSUnknown: No CSSUnknown found.', 84 error=xml.dom.InvalidModificationErr) 85 return 86 87 newatkeyword = tokens[0].value[1:] 88 newseq = [] 89 expected = '' 90 for i in range(1, len(tokens)): 91 t = tokens[i] 92 if self._ttypes.EOF == t.type: 93 break 94 95 if self._ttypes.S == t.type: 96 newseq.append(t.value) # whitespace: add 97 98 elif self._ttypes.COMMENT == t.type: 99 # Comment: just add 100 newseq.append(cssutils.css.CSSComment(t)) 101 102 # TODO: block or simple content ending with ; 103 104 elif self._ttypes.INVALID == t.type: 105 self.valid = False 106 self._log.error(u'CSSUnknown: Invalid Token found.', t) 107 return 108 109 else: 110 newseq.append(t.value) 111 112 self.atkeyword = newatkeyword 113 self.seq = newseq
114 115 cssText = property(fget=_getCssText, fset=_setCssText, 116 doc="(DOM) The parsable textual representation.")
117 118 119 if __name__ == '__main__': 120 c = CSSUnknownRule('@x something /*comment*/;') 121 ## print c.seq 122 ## print c.cssText 123 ## print 124 ## c.cssText = u'@x { block /*comment*/ }' 125 ## print c.seq 126 ## print c.cssText 127 sheet = cssutils.parseString(u'''@three-dee { 128 @background-lighting { 129 azimuth : 30deg; 130 elevation : 190deg; 131 } 132 }''') 133 print "SHEET:", sheet.cssText 134