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: 2007-10-19 00:31:34 +0200 (Fr, 19 Okt 2007) $'
     9  __version__ = '$LastChangedRevision: 518 $'
    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, readonly=False):
    35          super(CSSComment, self).__init__()
    36
    37          if cssText:
    38              self._setCssText(cssText)
    39          else:
    40              self._cssText = None
    41
    42          self._readonly = readonly
    43
    44 -    def _getCssText(self):
    45          """returns serialized property cssText"""
    46          return cssutils.ser.do_CSSComment(self)
    47
    48 -    def _setCssText(self, cssText):
    49          """
    50          cssText
    51              textual text to set or tokenlist which is not tokenized
    52              anymore. May also be a single token for this rule
    53          parser
    54              if called from cssparser directly this is Parser instance
    55
    56          DOMException on setting
    57
    58          - SYNTAX_ERR: (self)
    59            Raised if the specified CSS string value has a syntax error and
    60            is unparsable.
    61          - INVALID_MODIFICATION_ERR: (self)
    62            Raised if the specified CSS string value represents a different
    63            type of rule than the current one.
    64          - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
    65            Raised if the rule is readonly.
    66          """
    67          super(CSSComment, self)._setCssText(cssText)
    68          tokenizer = self._tokenize2(cssText)
    69
    70          commenttoken = self._nexttoken(tokenizer)
    71          unexpected = self._nexttoken(tokenizer)
    72
    73          if not commenttoken or\
    74             self._type(commenttoken) != self._prods.COMMENT or\
    75             unexpected:
    76              self._log.error(u'CSSComment: Not a CSSComment: %r' %
    77                  self._valuestr(cssText),
    78                  error=xml.dom.InvalidModificationErr)
    79          else:
    80              self._cssText = self._tokenvalue(commenttoken)
    81
    82      cssText = property(_getCssText, _setCssText,
    83          doc=u"(cssutils) Textual representation of this comment")
    84
    85 -    def __repr__(self):
    86          return "cssutils.css.%s(cssText=%r)" % (
    87                  self.__class__.__name__, self.cssText)
    88
    89 -    def __str__(self):
    90          return "<cssutils.css.%s object cssText=%r at 0x%x>" % (
    91                  self.__class__.__name__, self.cssText, id(self))
    92