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