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-10-19 00:31:34 +0200 (Fr, 19 Okt 2007) $' 
  6  __version__ = '$LastChangedRevision: 518 $' 
  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 # currently not implemented 59 PAGE_RULE = 6 60 NAMESPACE_RULE = 7 # cssutils only, WD, may be different later 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, readonly=False):
78 super(CSSRule, self).__init__() 79 self.parentRule = None 80 self.parentStyleSheet = None 81 self.seq = [] 82 self.valid = True 83 # must be set after initialization of #inheriting rule is done 84 self._readonly = False
85
86 - def _getCssText(self):
87 return u''
88
89 - def _setCssText(self, cssText):
90 """ 91 DOMException on setting 92 93 - SYNTAX_ERR: 94 Raised if the specified CSS string value has a syntax error and 95 is unparsable. 96 - INVALID_MODIFICATION_ERR: 97 Raised if the specified CSS string value represents a different 98 type of rule than the current one. 99 - HIERARCHY_REQUEST_ERR: 100 Raised if the rule cannot be inserted at this point in the 101 style sheet. 102 - NO_MODIFICATION_ALLOWED_ERR: (self) 103 Raised if the rule is readonly. 104 """ 105 self._checkReadonly()
106 107 cssText = property(fget=_getCssText, fset=_setCssText, 108 doc="""(DOM) The parsable textual representation of the rule. This 109 reflects the current state of the rule and not its initial value. 110 The initial value is saved, but this may be removed in a future 111 version! 112 MUST BE OVERWRITTEN IN SUBCLASS TO WORK!""") 113
114 - def _getTypeString(self):
115 return CSSRule._typestrings[self.type]
116 117 typeString = property(_getTypeString, doc="Name of this rules type.")
118