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: 2007-08-08 15:17:08 +0200 (Mi, 08 Aug 2007) $' 
  6  __version__ = '$LastChangedRevision: 193 $' 
  7   
  8  import xml.dom 
  9  import cssutils 
 10   
11 -class CSSRule(cssutils.util.Base):
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: 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 valid: 45 if this 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 54 STYLE_RULE = 1 55 CHARSET_RULE = 2 56 IMPORT_RULE = 3 57 MEDIA_RULE = 4 58 FONT_FACE_RULE = 5 59 "Not in CSS 2.1 specification and not implemented" 60 PAGE_RULE = 6 61 NAMESPACE_RULE = 7 62 "TODO: WD, may be different later" 63 "cssutils only" 64 65 _typestrings = ['UNKNOWN_RULE', 'STYLE_RULE', 'CHARSET_RULE', 'IMPORT_RULE', 66 'MEDIA_RULE', 'FONT_FACE_RULE', 'PAGE_RULE', 'NAMESPACE_RULE', 67 'COMMENT'] 68 69 type = UNKNOWN_RULE 70 """ 71 The type of this rule, as defined by a CSSRule type constant. 72 Overwritten in derived classes. 73 74 The expectation is that binding-specific casting methods can be used to 75 cast down from an instance of the CSSRule interface to the specific 76 derived interface implied by the type. 77 (Casting not for this Python implementation I guess...) 78 """ 79
80 - def __init__(self, readonly=False):
81 super(CSSRule, self).__init__() 82 83 self.parentRule = None 84 self.parentStyleSheet = None 85 86 self.seq = [] 87 self.valid = True 88 89 # must be set after initialization of #inheriting rule 90 self._readonly = False
91
92 - def _getCssText(self):
93 return u''
94
95 - def _setCssText(self, cssText):
96 """ 97 DOMException on setting 98 99 - SYNTAX_ERR: 100 Raised if the specified CSS string value has a syntax error and 101 is unparsable. 102 - INVALID_MODIFICATION_ERR: 103 Raised if the specified CSS string value represents a different 104 type of rule than the current one. 105 - HIERARCHY_REQUEST_ERR: 106 Raised if the rule cannot be inserted at this point in the 107 style sheet. 108 - NO_MODIFICATION_ALLOWED_ERR: (self) 109 Raised if the rule is readonly. 110 """ 111 self._checkReadonly()
112 113 cssText = property(fget=_getCssText, fset=_setCssText, 114 doc="""(DOM) The parsable textual representation of the rule. This 115 reflects the current state of the rule and not its initial value. 116 The initial value is saved, but this may be removed in a future 117 version! 118 MUST BE OVERWRITTEN IN SUBCLASS TO WORK!""") 119
120 - def _getTypeString(self):
121 return CSSRule._typestrings[self.type]
122 123 typeString = property(_getTypeString, doc="Name of this rules type.")
124