1 """CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule.
2 """
3 __all__ = ['CSSUnknownRule']
4 __docformat__ = 'restructuredtext'
5 __author__ = '$LastChangedBy: cthedot $'
6 __date__ = '$LastChangedDate: 2008-01-27 17:28:41 +0100 (So, 27 Jan 2008) $'
7 __version__ = '$LastChangedRevision: 950 $'
8
9 import xml.dom
10 import cssrule
11 import cssutils
12
14 """
15 represents an at-rule not supported by this user agent.
16
17 Properties
18 ==========
19 inherited from CSSRule
20 - cssText
21 - type
22
23 cssutils only
24 -------------
25 atkeyword:
26 the literal keyword used
27 seq: a list (cssutils)
28 All parts of this rule excluding @KEYWORD but including CSSComments
29
30 Format
31 ======
32 unknownrule:
33 @xxx until ';' or block {...}
34 """
35 type = cssrule.CSSRule.UNKNOWN_RULE
36
37 - def __init__(self, cssText=u'', parentRule=None,
38 parentStyleSheet=None, readonly=False):
52
53
54 - def _getCssText(self):
55 """ returns serialized property cssText """
56 return cssutils.ser.do_CSSUnknownRule(self)
57
58 - def _setCssText(self, cssText):
59 """
60 DOMException on setting
61
62 - SYNTAX_ERR:
63 Raised if the specified CSS string value has a syntax error and
64 is unparsable.
65 - INVALID_MODIFICATION_ERR:
66 Raised if the specified CSS string value represents a different
67 type of rule than the current one.
68 - HIERARCHY_REQUEST_ERR: (never raised)
69 Raised if the rule cannot be inserted at this point in the
70 style sheet.
71 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
72 Raised if the rule is readonly.
73 """
74 super(CSSUnknownRule, self)._setCssText(cssText)
75 tokenizer = self._tokenize2(cssText)
76 attoken = self._nexttoken(tokenizer, None)
77 if not attoken or 'ATKEYWORD' != self._type(attoken):
78 self._log.error(u'CSSUnknownRule: No CSSUnknownRule found.',
79 error=xml.dom.InvalidModificationErr)
80 else:
81 newatkeyword = self._tokenvalue(attoken)
82 newseq = []
83 for token in tokenizer:
84 if 'INVALID' == self._type(token):
85 return
86 newseq.append(self._tokenvalue(token))
87
88 self.atkeyword = newatkeyword
89 self.seq = newseq
90
91 cssText = property(fget=_getCssText, fset=_setCssText,
92 doc="(DOM) The parsable textual representation.")
93
95 return "cssutils.css.%s(cssText=%r)" % (
96 self.__class__.__name__, self.cssText)
97
99 return "<cssutils.css.%s object cssText=%r at 0x%x>" % (
100 self.__class__.__name__, self.cssText, id(self))
101