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. 
 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: 2007-08-20 22:07:12 +0200 (Mo, 20 Aug 2007) $' 
 9  __version__ = '$LastChangedRevision: 257 $' 
10   
11  import xml.dom 
12   
13  import cssrule 
14  import cssutils 
15   
16   
17 -class CSSComment(cssrule.CSSRule):
18 """ 19 (cssutils) a CSS comment 20 21 Properties 22 ========== 23 cssText: of type DOMString 24 The comment text including comment delimiters 25 26 Inherits properties from CSSRule 27 28 Format 29 ====== 30 :: 31 32 /*...*/ 33 """ 34 type = cssrule.CSSRule.COMMENT # value = -1 35
36 - def __init__(self, cssText=None, readonly=False):
37 super(CSSComment, self).__init__() 38 39 if cssText: 40 self._setCssText(cssText) 41 else: 42 self._cssText = None 43 44 self._readonly = readonly
45 46
47 - def _getCssText(self):
48 """returns serialized property cssText""" 49 return cssutils.ser.do_CSSComment(self)
50
51 - def _setCssText(self, cssText):
52 """ 53 cssText 54 textual text to set or tokenlist which is not tokenized 55 anymore. May also be a single token for this rule 56 parser 57 if called from cssparser directly this is Parser instance 58 59 DOMException on setting 60 61 - SYNTAX_ERR: (self) 62 Raised if the specified CSS string value has a syntax error and 63 is unparsable. 64 - INVALID_MODIFICATION_ERR: (self) 65 Raised if the specified CSS string value represents a different 66 type of rule than the current one. 67 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule) 68 Raised if the rule is readonly. 69 """ 70 super(CSSComment, self)._setCssText(cssText) 71 tokens = self._tokenize(cssText) 72 73 if not tokens or tokens[0].type != self._ttypes.COMMENT: 74 self._log.error(u'CSSComent: Not a CSSComment: %s' % 75 self._valuestr(cssText), 76 error=xml.dom.InvalidModificationErr) 77 elif len(tokens) > 1: 78 self._log.error( 79 u'CSSComment: Syntax error. %s' % self._valuestr( 80 cssText)) 81 else: 82 token = tokens[0] 83 self._cssText = token.value
84 85 cssText = property(_getCssText, _setCssText, 86 doc=u"(cssutils) Textual representation of this comment") 87
88 - def __repr__(self):
89 return "cssutils.css.%s(cssText=%r)" % ( 90 self.__class__.__name__, self.cssText)
91
92 - def __str__(self):
93 return "<cssutils.css.%s object at 0x%x>" % ( 94 self.__class__.__name__, id(self))
95