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

Source Code for Module cssutils.css.csscomment

 1  """CSSComment is not defined in DOM Level 2 at all but a cssutils defined 
 2  class only. 
 3  Implements CSSRule which is also extended for a CSSComment rule type 
 4  """ 
 5  __all__ = ['CSSComment'] 
 6  __docformat__ = 'restructuredtext' 
 7  __author__ = '$LastChangedBy: cthedot $' 
 8  __date__ = '$LastChangedDate: 2008-01-27 17:28:41 +0100 (So, 27 Jan 2008) $' 
 9  __version__ = '$LastChangedRevision: 950 $' 
10   
11  import xml.dom 
12  import cssrule 
13  import cssutils 
14   
15 -class CSSComment(cssrule.CSSRule):
16 """ 17 (cssutils) a CSS comment 18 19 Properties 20 ========== 21 cssText: of type DOMString 22 The comment text including comment delimiters 23 24 Inherits properties from CSSRule 25 26 Format 27 ====== 28 :: 29 30 /*...*/ 31 """ 32 type = cssrule.CSSRule.COMMENT # value = -1 33
34 - def __init__(self, cssText=None, parentRule=None, 35 parentStyleSheet=None, readonly=False):
36 super(CSSComment, self).__init__(parentRule=parentRule, 37 parentStyleSheet=parentStyleSheet) 38 39 self._cssText = None 40 if cssText: 41 self._setCssText(cssText) 42 43 self._readonly = readonly
44
45 - def _getCssText(self):
46 """returns serialized property cssText""" 47 return cssutils.ser.do_CSSComment(self)
48
49 - def _setCssText(self, cssText):
50 """ 51 cssText 52 textual text to set or tokenlist which is not tokenized 53 anymore. May also be a single token for this rule 54 parser 55 if called from cssparser directly this is Parser instance 56 57 DOMException on setting 58 59 - SYNTAX_ERR: (self) 60 Raised if the specified CSS string value has a syntax error and 61 is unparsable. 62 - INVALID_MODIFICATION_ERR: (self) 63 Raised if the specified CSS string value represents a different 64 type of rule than the current one. 65 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule) 66 Raised if the rule is readonly. 67 """ 68 super(CSSComment, self)._setCssText(cssText) 69 tokenizer = self._tokenize2(cssText) 70 71 commenttoken = self._nexttoken(tokenizer) 72 unexpected = self._nexttoken(tokenizer) 73 74 if not commenttoken or\ 75 self._type(commenttoken) != self._prods.COMMENT or\ 76 unexpected: 77 self._log.error(u'CSSComment: Not a CSSComment: %r' % 78 self._valuestr(cssText), 79 error=xml.dom.InvalidModificationErr) 80 else: 81 self._cssText = self._tokenvalue(commenttoken)
82 83 cssText = property(_getCssText, _setCssText, 84 doc=u"(cssutils) Textual representation of this comment") 85
86 - def __repr__(self):
87 return "cssutils.css.%s(cssText=%r)" % ( 88 self.__class__.__name__, self.cssText)
89
90 - def __str__(self):
91 return "<cssutils.css.%s object cssText=%r at 0x%x>" % ( 92 self.__class__.__name__, self.cssText, id(self))
93