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

Source Code for Module cssutils.css.cssrule

  1  """CSSRule implements DOM Level 2 CSS CSSRule.""" 
  2  __all__ = ['CSSRule'] 
  3  __docformat__ = 'restructuredtext' 
  4  __version__ = '$Id: cssrule.py 1177 2008-03-20 17:47:23Z cthedot $' 
  5   
  6  import xml.dom 
  7  import cssutils 
  8   
9 -class CSSRule(cssutils.util.Base2):
10 """ 11 Abstract base interface for any type of CSS statement. This includes 12 both rule sets and at-rules. An implementation is expected to preserve 13 all rules specified in a CSS style sheet, even if the rule is not 14 recognized by the parser. Unrecognized rules are represented using the 15 CSSUnknownRule interface. 16 17 Properties 18 ========== 19 cssText: of type DOMString 20 The parsable textual representation of the rule. This reflects the 21 current state of the rule and not its initial value. 22 parentRule: of type CSSRule, readonly 23 If this rule is contained inside another rule (e.g. a style rule 24 inside an @media block), this is the containing rule. If this rule 25 is not nested inside any other rules, this returns None. 26 parentStyleSheet: of type CSSStyleSheet, readonly 27 The style sheet that contains this rule. 28 type: of type unsigned short, readonly 29 The type of the rule, as defined above. The expectation is that 30 binding-specific casting methods can be used to cast down from an 31 instance of the CSSRule interface to the specific derived interface 32 implied by the type. 33 34 cssutils only 35 ------------- 36 seq (READONLY): 37 contains sequence of parts of the rule including comments but 38 excluding @KEYWORD and braces 39 typeString: string 40 A string name of the type of this rule, e.g. 'STYLE_RULE'. Mainly 41 useful for debugging 42 wellformed: 43 if a rule is valid 44 """ 45 46 """ 47 CSSRule type constants. 48 An integer indicating which type of rule this is. 49 """ 50 COMMENT = -1 # cssutils only 51 UNKNOWN_RULE = 0 #u 52 STYLE_RULE = 1 #s 53 CHARSET_RULE = 2 #c 54 IMPORT_RULE = 3 #i 55 MEDIA_RULE = 4 #m 56 FONT_FACE_RULE = 5 #f 57 PAGE_RULE = 6 #p 58 NAMESPACE_RULE = 7 # CSSOM 59 60 _typestrings = ['UNKNOWN_RULE', 'STYLE_RULE', 'CHARSET_RULE', 'IMPORT_RULE', 61 'MEDIA_RULE', 'FONT_FACE_RULE', 'PAGE_RULE', 'NAMESPACE_RULE', 62 'COMMENT'] 63 64 type = UNKNOWN_RULE 65 """ 66 The type of this rule, as defined by a CSSRule type constant. 67 Overwritten in derived classes. 68 69 The expectation is that binding-specific casting methods can be used to 70 cast down from an instance of the CSSRule interface to the specific 71 derived interface implied by the type. 72 (Casting not for this Python implementation I guess...) 73 """ 74
75 - def __init__(self, parentRule=None, parentStyleSheet=None, readonly=False):
76 """ 77 set common attributes for all rules 78 """ 79 super(CSSRule, self).__init__() 80 self._parentRule = parentRule 81 self._parentStyleSheet = parentStyleSheet 82 self._setSeq(self._tempSeq()) 83 # must be set after initialization of #inheriting rule is done 84 self._readonly = False
85
86 - def _setCssText(self, cssText):
87 """ 88 DOMException on setting 89 90 - SYNTAX_ERR: 91 Raised if the specified CSS string value has a syntax error and 92 is unparsable. 93 - INVALID_MODIFICATION_ERR: 94 Raised if the specified CSS string value represents a different 95 type of rule than the current one. 96 - HIERARCHY_REQUEST_ERR: 97 Raised if the rule cannot be inserted at this point in the 98 style sheet. 99 - NO_MODIFICATION_ALLOWED_ERR: (self) 100 Raised if the rule is readonly. 101 """ 102 self._checkReadonly()
103 104 cssText = property(lambda self: u'', _setCssText, 105 doc="""(DOM) The parsable textual representation of the rule. This 106 reflects the current state of the rule and not its initial value. 107 The initial value is saved, but this may be removed in a future 108 version! 109 MUST BE OVERWRITTEN IN SUBCLASS TO WORK!""") 110
111 - def _setAtkeyword(self, akw):
112 """checks if new keyword is normalized same as old""" 113 if not self.atkeyword or (self._normalize(akw) == 114 self._normalize(self.atkeyword)): 115 self._atkeyword = akw 116 else: 117 self._log.error(u'%s: Invalid atkeyword for this rule: %r' % 118 (self._normalize(self.atkeyword), akw), 119 error=xml.dom.InvalidModificationErr)
120 121 atkeyword = property(lambda self: self._atkeyword, _setAtkeyword, 122 doc=u"@keyword for @rules") 123 124 parentRule = property(lambda self: self._parentRule, 125 doc=u"READONLY") 126 127 parentStyleSheet = property(lambda self: self._parentStyleSheet, 128 doc=u"READONLY") 129 130 wellformed = property(lambda self: False, 131 doc=u"READONLY") 132 133 typeString = property(lambda self: CSSRule._typestrings[self.type], 134 doc="Name of this rules type.")
135