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