1
"""CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule."""
2
__all__ = ['CSSUnknownRule']
3
__docformat__ = 'restructuredtext'
4
__version__ = '$Id: cssunknownrule.py 1949 2010-03-26 22:16:33Z cthedot $'
10
class CSSUnknownRule(cssrule.CSSRule):
12
Represents an at-rule not supported by this user agent, so in
13
effect all other at-rules not defined in cssutils.
17
@xxx until ';' or block {...}
19
def __init__(self, cssText=u'', parentRule=None,
20
parentStyleSheet=None, readonly=False):
25
super(CSSUnknownRule, self).__init__(parentRule=parentRule,
26
parentStyleSheet=parentStyleSheet)
27
self._atkeyword = None
29
self.cssText = cssText
31
self._readonly = readonly
34
return u"cssutils.css.%s(cssText=%r)" % (
35
self.__class__.__name__,
39
return u"<cssutils.css.%s object cssText=%r at 0x%x>" % (
40
self.__class__.__name__,
44
def _getCssText(self):
45
"""Return serialized property cssText."""
46
return cssutils.ser.do_CSSUnknownRule(self)
48
def _setCssText(self, cssText):
51
- :exc:`~xml.dom.SyntaxErr`:
52
Raised if the specified CSS string value has a syntax error and
54
- :exc:`~xml.dom.InvalidModificationErr`:
55
Raised if the specified CSS string value represents a different
56
type of rule than the current one.
57
- :exc:`~xml.dom.HierarchyRequestErr`:
58
Raised if the rule cannot be inserted at this point in the
60
- :exc:`~xml.dom.NoModificationAllowedErr`:
61
Raised if the rule is readonly.
63
super(CSSUnknownRule, self)._setCssText(cssText)
64
tokenizer = self._tokenize2(cssText)
65
attoken = self._nexttoken(tokenizer, None)
66
if not attoken or self._type(attoken) != self._prods.ATKEYWORD:
67
self._log.error(u'CSSUnknownRule: No CSSUnknownRule found: %s' %
68
self._valuestr(cssText),
69
error=xml.dom.InvalidModificationErr)
71
# for closures: must be a mutable
72
new = {'nesting': [], # {} [] or ()
76
def CHAR(expected, seq, token, tokenizer=None):
77
type_, val, line, col = token
80
new['nesting'].append(val)
82
opening = {u'}': u'{', u']': u'[', u')': u'('}[val]
84
if new['nesting'][-1] == opening:
89
new['wellformed'] = False
90
self._log.error(u'CSSUnknownRule: Wrong nesting of '
91
u'{, [ or (.', token=token)
93
if val in u'};' and not new['nesting']:
96
seq.append(val, type_, line=line, col=col)
99
new['wellformed'] = False
100
self._log.error(u'CSSUnknownRule: Expected end of rule.',
104
def FUNCTION(expected, seq, token, tokenizer=None):
105
# handled as opening (
106
type_, val, line, col = token
107
val = self._tokenvalue(token)
108
if expected != 'EOF':
109
new['nesting'].append(u'(')
110
seq.append(val, type_, line=line, col=col)
113
new['wellformed'] = False
114
self._log.error(u'CSSUnknownRule: Expected end of rule.',
118
def EOF(expected, seq, token, tokenizer=None):
119
"close all blocks and return 'EOF'"
120
for x in reversed(new['nesting']):
121
closing = {u'{': u'}', u'[': u']', u'(': u')'}[x]
122
seq.append(closing, closing)
126
def INVALID(expected, seq, token, tokenizer=None):
128
self._log.error(u'CSSUnknownRule: Bad syntax.',
129
token=token, error=xml.dom.SyntaxErr)
130
new['wellformed'] = False
133
def STRING(expected, seq, token, tokenizer=None):
134
type_, val, line, col = token
135
val = self._stringtokenvalue(token)
136
if expected != 'EOF':
137
seq.append(val, type_, line=line, col=col)
140
new['wellformed'] = False
141
self._log.error(u'CSSUnknownRule: Expected end of rule.',
145
def URI(expected, seq, token, tokenizer=None):
146
type_, val, line, col = token
147
val = self._uritokenvalue(token)
148
if expected != 'EOF':
149
seq.append(val, type_, line=line, col=col)
152
new['wellformed'] = False
153
self._log.error(u'CSSUnknownRule: Expected end of rule.',
157
def default(expected, seq, token, tokenizer=None):
158
type_, val, line, col = token
159
if expected != 'EOF':
160
seq.append(val, type_, line=line, col=col)
163
new['wellformed'] = False
164
self._log.error(u'CSSUnknownRule: Expected end of rule.',
168
# unknown : ATKEYWORD S* ... ; | }
169
newseq = self._tempSeq()
170
wellformed, expected = self._parse(expected=None,
171
seq=newseq, tokenizer=tokenizer,
172
productions={'CHAR': CHAR,
174
'FUNCTION': FUNCTION,
178
'S': default # overwrite default default!
183
# wellformed set by parse
184
wellformed = wellformed and new['wellformed']
187
if expected != 'EOF':
189
self._log.error(u'CSSUnknownRule: No ending ";" or "}" found: '
190
u'%r' % self._valuestr(cssText))
193
self._log.error(u'CSSUnknownRule: Unclosed "{", "[" or "(": %r'
194
% self._valuestr(cssText))
198
self.atkeyword = self._tokenvalue(attoken)
201
cssText = property(fget=_getCssText, fset=_setCssText,
202
doc=u"(DOM) The parsable textual representation.")
204
type = property(lambda self: self.UNKNOWN_RULE,
205
doc=u"The type of this rule, as defined by a CSSRule "
208
wellformed = property(lambda self: bool(self.atkeyword))
b'\\ No newline at end of file'