1 """CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule.
2 """
3 __all__ = ['CSSUnknownRule']
4 __docformat__ = 'restructuredtext'
5 __author__ = '$LastChangedBy: doerwalter $'
6 __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $'
7 __version__ = '0.9.2a5, $LastChangedRevision: 160 $'
8
9 import xml.dom
10
11 import cssrule
12 import cssutils
13
14
16 """
17 represents an at-rule not supported by this user agent.
18
19 Properties
20 ==========
21 atkeyword
22 keyword used including @, e.g. @-moz-unknown
23 cssText: of type DOMString
24 The parsable textual representation of this rule
25 seq: a list (cssutils)
26 All parts of this rule excluding @KEYWORD but including CSSComments
27 type: see CSSRule
28 The typecode for this rule
29
30 cssutils only
31 -------------
32 atkeyword:
33 the literal keyword used
34
35 Inherits properties from CSSRule
36
37 Format
38 ======
39 unknownrule:
40 @xxx until ';' or block {...}
41 """
42 type = cssrule.CSSRule.UNKNOWN_RULE
43
44 - def __init__(self, cssText=u'', readonly=False):
57
58
59 - def _getCssText(self):
60 """ returns serialized property cssText """
61 return cssutils.ser.do_CSSUnknownRule(self)
62
63 - def _setCssText(self, cssText):
64 """
65 DOMException on setting
66
67 - SYNTAX_ERR:
68 Raised if the specified CSS string value has a syntax error and
69 is unparsable.
70 - INVALID_MODIFICATION_ERR:
71 Raised if the specified CSS string value represents a different
72 type of rule than the current one.
73 - HIERARCHY_REQUEST_ERR: (never raised)
74 Raised if the rule cannot be inserted at this point in the
75 style sheet.
76 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
77 Raised if the rule is readonly.
78 """
79 super(CSSUnknownRule, self)._setCssText(cssText)
80 tokens = self._tokenize(cssText)
81
82 if not tokens or tokens and tokens[0].type != self._ttypes.ATKEYWORD:
83 self._log.error(u'CSSUnknown: No CSSUnknown found.',
84 error=xml.dom.InvalidModificationErr)
85 return
86
87 newatkeyword = tokens[0].value[1:]
88 newseq = []
89 expected = ''
90 for i in range(1, len(tokens)):
91 t = tokens[i]
92 if self._ttypes.EOF == t.type:
93 break
94
95 if self._ttypes.S == t.type:
96 newseq.append(t.value)
97
98 elif self._ttypes.COMMENT == t.type:
99
100 newseq.append(cssutils.css.CSSComment(t))
101
102
103
104 elif self._ttypes.INVALID == t.type:
105 self.valid = False
106 self._log.error(u'CSSUnknown: Invalid Token found.', t)
107 return
108
109 else:
110 newseq.append(t.value)
111
112 self.atkeyword = newatkeyword
113 self.seq = newseq
114
115 cssText = property(fget=_getCssText, fset=_setCssText,
116 doc="(DOM) The parsable textual representation.")
117
118
119 if __name__ == '__main__':
120 c = CSSUnknownRule('@x something /*comment*/;')
121
122
123
124
125
126
127 sheet = cssutils.parseString(u'''@three-dee {
128 @background-lighting {
129 azimuth : 30deg;
130 elevation : 190deg;
131 }
132 }''')
133 print "SHEET:", sheet.cssText
134