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-02-12 23:43:05 +0100 (Di, 12 Feb 2008) $'
     9  __version__ = '$LastChangedRevision: 1049 $'
    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      # constant but needed:
    34      wellformed = True
    35
    36 -    def __init__(self, cssText=None, parentRule=None,
    37                   parentStyleSheet=None, readonly=False):
    38          super(CSSComment, self).__init__(parentRule=parentRule,
    39                                           parentStyleSheet=parentStyleSheet)
    40
    41          self._cssText = None
    42          if cssText:
    43              self._setCssText(cssText)
    44
    45          self._readonly = readonly
    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          tokenizer = self._tokenize2(cssText)
    72
    73          commenttoken = self._nexttoken(tokenizer)
    74          unexpected = self._nexttoken(tokenizer)
    75
    76          if not commenttoken or\
    77             self._type(commenttoken) != self._prods.COMMENT or\
    78             unexpected:
    79              self._log.error(u'CSSComment: Not a CSSComment: %r' %
    80                  self._valuestr(cssText),
    81                  error=xml.dom.InvalidModificationErr)
    82          else:
    83              self._cssText = self._tokenvalue(commenttoken)
    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 cssText=%r at 0x%x>" % (
    94                  self.__class__.__name__, self.cssText, id(self))
    95