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  __version__ = '$Id: csscomment.py 1170 2008-03-20 17:42:07Z cthedot $'
     8
     9  import xml.dom
    10  import cssrule
    11  import cssutils
    12
    13 -class CSSComment(cssrule.CSSRule):
    14      """
    15      (cssutils) a CSS comment
    16
    17      Properties
    18      ==========
    19      cssText: of type DOMString
    20          The comment text including comment delimiters
    21
    22      Inherits properties from CSSRule
    23
    24      Format
    25      ======
    26      ::
    27
    28          /*...*/
    29      """
    30      type = property(lambda self: cssrule.CSSRule.COMMENT) # value = -1
    31      # constant but needed:
    32      wellformed = True
    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