1 """CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule.
2 """
3 __all__ = ['CSSUnknownRule']
4 __docformat__ = 'restructuredtext'
5 __author__ = '$LastChangedBy: cthedot $'
6 __date__ = '$LastChangedDate: 2007-10-19 00:31:34 +0200 (Fr, 19 Okt 2007) $'
7 __version__ = '$LastChangedRevision: 518 $'
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'', readonly=False):
38 """
39 cssText
40 of type string
41 """
42 super(CSSUnknownRule, self).__init__()
43
44 self.valid = True
45 if cssText:
46 self.cssText = cssText
47 else:
48 self.atkeyword = None
49
50 self._readonly = readonly
51
52
53 - def _getCssText(self):
54 """ returns serialized property cssText """
55 return cssutils.ser.do_CSSUnknownRule(self)
56
57 - def _setCssText(self, cssText):
58 """
59 DOMException on setting
60
61 - SYNTAX_ERR:
62 Raised if the specified CSS string value has a syntax error and
63 is unparsable.
64 - INVALID_MODIFICATION_ERR:
65 Raised if the specified CSS string value represents a different
66 type of rule than the current one.
67 - HIERARCHY_REQUEST_ERR: (never raised)
68 Raised if the rule cannot be inserted at this point in the
69 style sheet.
70 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
71 Raised if the rule is readonly.
72 """
73 super(CSSUnknownRule, self)._setCssText(cssText)
74 tokenizer = self._tokenize2(cssText)
75 attoken = self._nexttoken(tokenizer, None)
76 if not attoken or 'ATKEYWORD' != self._type(attoken):
77 self._log.error(u'CSSUnknownRule: No CSSUnknownRule found.',
78 error=xml.dom.InvalidModificationErr)
79 else:
80 newatkeyword = self._tokenvalue(attoken)
81 newseq = []
82 for token in tokenizer:
83 if 'INVALID' == self._type(token):
84 return
85 newseq.append(self._tokenvalue(token))
86
87 self.atkeyword = newatkeyword
88 self.seq = newseq
89
90 cssText = property(fget=_getCssText, fset=_setCssText,
91 doc="(DOM) The parsable textual representation.")
92
94 return "cssutils.css.%s(cssText=%r)" % (
95 self.__class__.__name__, self.cssText)
96
98 return "<cssutils.css.%s object cssText=%r at 0x%x>" % (
99 self.__class__.__name__, self.cssText, id(self))
100