Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / cssutils / css / csscomment.py @ 475

History | View | Annotate | Download (2.77 KB)

1
"""CSSComment is not defined in DOM Level 2 at all but a cssutils defined
2
class only.
3

4
Implements CSSRule which is also extended for a CSSComment rule type.
5
"""
6
__all__ = ['CSSComment']
7
__docformat__ = 'restructuredtext'
8
__version__ = '$Id$'
9

    
10
import cssrule
11
import cssutils
12
import xml.dom
13

    
14
class CSSComment(cssrule.CSSRule):
15
    """
16
    Represents a CSS comment (cssutils only).
17

18
    Format::
19

20
        /*...*/
21
    """
22
    def __init__(self, cssText=None, parentRule=None, 
23
                 parentStyleSheet=None, readonly=False):
24
        super(CSSComment, self).__init__(parentRule=parentRule, 
25
                                         parentStyleSheet=parentStyleSheet)
26

    
27
        self._cssText = None
28
        if cssText:
29
            self._setCssText(cssText)
30

    
31
        self._readonly = readonly
32

    
33
    def __repr__(self):
34
        return u"cssutils.css.%s(cssText=%r)" % (
35
                self.__class__.__name__, 
36
                self.cssText)
37

    
38
    def __str__(self):
39
        return u"<cssutils.css.%s object cssText=%r at 0x%x>" % (
40
                self.__class__.__name__, 
41
                self.cssText, 
42
                id(self))
43

    
44
    def _getCssText(self):
45
        """Return serialized property cssText."""
46
        return cssutils.ser.do_CSSComment(self)
47

    
48
    def _setCssText(self, cssText):
49
        """
50
        :param cssText:
51
            textual text to set or tokenlist which is not tokenized
52
            anymore. May also be a single token for this rule
53

54
        :exceptions:
55
            - :exc:`~xml.dom.SyntaxErr`:
56
              Raised if the specified CSS string value has a syntax error and
57
              is unparsable.
58
            - :exc:`~xml.dom.InvalidModificationErr`:
59
              Raised if the specified CSS string value represents a different
60
              type of rule than the current one.
61
            - :exc:`~xml.dom.NoModificationAllowedErr`:
62
              Raised if the rule is readonly.
63
        """
64
        super(CSSComment, self)._setCssText(cssText)
65
        tokenizer = self._tokenize2(cssText)
66

    
67
        commenttoken = self._nexttoken(tokenizer)
68
        unexpected = self._nexttoken(tokenizer)
69

    
70
        if not commenttoken or\
71
           self._type(commenttoken) != self._prods.COMMENT or\
72
           unexpected:
73
            self._log.error(u'CSSComment: Not a CSSComment: %r' %
74
                self._valuestr(cssText),
75
                error=xml.dom.InvalidModificationErr)
76
        else:
77
            self._cssText = self._tokenvalue(commenttoken)
78

    
79
    cssText = property(_getCssText, _setCssText,
80
        doc=u"The parsable textual representation of this rule.")
81

    
82
    type = property(lambda self: self.COMMENT, 
83
                    doc=u"The type of this rule, as defined by a CSSRule "
84
                        u"type constant.")
85
    
86
    # constant but needed:
87
    wellformed = property(lambda self: True)