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