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