1
2
3
4
5 import sys
6 import codecs
7 import optparse
8 import cStringIO
9 from Ft.Xml import InputSource, CreateInputSource
10 from Ft.Xml.Xslt import PatternList, parser
11 from Ft.Xml.Xslt import Stylesheet, Processor, OutputHandler, OutputParameters
12 from Ft.Xml.XPath import Compile as CompileXPath
13 from Ft.Xml.XPath.Context import Context as XPathContext
14 from Ft.Xml.Xslt.XsltContext import XsltContext
15 from Ft.Xml.Domlette import NonvalidatingReader, GetAllNs
16 from Ft.Xml.XPath import Conversions
17 from Ft.Xml.XPath import Util
18 from Ft.Xml.XPath import CoreFunctions
19
20 from Ft.Xml.Xslt.XmlWriter import XmlWriter
21 from Ft.Xml.Xslt.OutputParameters import OutputParameters
22 from Ft.Xml.Xslt import XsltFunctions, Exslt
23 from Ft.Lib import Uri
24
25 from amara import domtools
26
27 XPATTERN_PARSER = parser.new()
28 del parser
29
30
31
32 STRON_BASE_URI = 'urn:uuid:365f5cea-67a0-4ed2-aba5-624f7b56edc5'
33 QUERY_BINDING = u'xslt'
34
35
37
38 vars = {}
39 xpath_ctx = XsltContext(node, processor=key_handler,
40 processorNss=NSS, varBindings=vars,
41 currentNode=node
42 )
43 xpath_ctx.currentInstruction = faux_instruction()
44 xpath_ctx.functions = FUNCTIONS
45 expr = CompileXPath(u'count(atom:id) = 1')
46 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
47 WRITER.text(u'Assertion failure:\n')
48 WRITER.text(u'An atom feed must have one and only one atom:id\n element. (RFC 4287, sec.4.1.1)')
49 WRITER.text(u'\n')
50 WRITER.text(u'\n')
51 expr = CompileXPath(u'count(atom:title) = 1')
52 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
53 WRITER.text(u'Assertion failure:\n')
54 WRITER.text(u'An atom feed must have one and only one\n atom:title element. (RFC 4287, sec.4.1.1)')
55 WRITER.text(u'\n')
56 WRITER.text(u'\n')
57 expr = CompileXPath(u'count(atom:updated) = 1')
58 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
59 WRITER.text(u'Assertion failure:\n')
60 WRITER.text(u'An atom feed must have one and only one\n atom:updated element. (RFC 4287, sec.4.1.1)')
61 WRITER.text(u'\n')
62 WRITER.text(u'\n')
63 expr = CompileXPath(u'atom:author or not(atom:entry[not(atom:author)])')
64 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
65 WRITER.text(u'Assertion failure:\n')
66 WRITER.text(u'An atom:feed must\n have an atom:author unless all of its atom:entry children have an atom:author. (RFC\n 4287, sec.4.1.1)')
67 WRITER.text(u'\n')
68 WRITER.text(u'\n')
69 expr = CompileXPath(u'count(atom:generator) <= 1')
70 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
71 WRITER.text(u'Assertion failure:\n')
72 WRITER.text(u'An atom feed cannot have more than\n one atom:generator element. (RFC 4287, sec.4.1.1)')
73 WRITER.text(u'\n')
74 WRITER.text(u'\n')
75 expr = CompileXPath(u'count(atom:icon) <= 1')
76 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
77 WRITER.text(u'Assertion failure:\n')
78 WRITER.text(u'An atom feed cannot have more than one\n atom:icon element. (RFC 4287, sec.4.1.1)')
79 WRITER.text(u'\n')
80 WRITER.text(u'\n')
81 expr = CompileXPath(u'count(atom:logo) <= 1')
82 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
83 WRITER.text(u'Assertion failure:\n')
84 WRITER.text(u'An atom feed cannot have more than one\n atom:logo element. (RFC 4287, sec.4.1.1)')
85 WRITER.text(u'\n')
86 WRITER.text(u'\n')
87 expr = CompileXPath(u'count(atom:rights) <= 1')
88 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
89 WRITER.text(u'Assertion failure:\n')
90 WRITER.text(u'An atom feed cannot have more than one\n atom:rights element. (RFC 4287, sec.4.1.1)')
91 WRITER.text(u'\n')
92 WRITER.text(u'\n')
93 expr = CompileXPath(u'count(atom:subtitle) <= 1')
94 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
95 WRITER.text(u'Assertion failure:\n')
96 WRITER.text(u'An atom feed cannot have more than\n one atom:subtitle element. (RFC 4287, sec.4.1.1)')
97 WRITER.text(u'\n')
98 WRITER.text(u'\n')
99 expr = CompileXPath(u'not(atom:published)')
100 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
101 WRITER.text(u'Assertion failure:\n')
102 WRITER.text(u'An atom feed cannot have an atom:published\n element. (RFC 4287, sec.4.1.1)')
103 WRITER.text(u'\n')
104 WRITER.text(u'\n')
105 expr = CompileXPath(u'not(atom:source)')
106 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
107 WRITER.text(u'Assertion failure:\n')
108 WRITER.text(u'An atom feed cannot have an atom:source element.\n (RFC 4287, sec.4.1.1)')
109 WRITER.text(u'\n')
110 WRITER.text(u'\n')
111
112 return
113
114
116
117 vars = {}
118 xpath_ctx = XsltContext(node, processor=key_handler,
119 processorNss=NSS, varBindings=vars,
120 currentNode=node
121 )
122 xpath_ctx.currentInstruction = faux_instruction()
123 xpath_ctx.functions = FUNCTIONS
124 expr = CompileXPath(u'@term')
125 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
126 WRITER.text(u'Assertion failure:\n')
127 WRITER.text(u'An atom:category element must have a term attribute. (RFC 4287,\n sec.4.2.2)')
128 WRITER.text(u'\n')
129 WRITER.text(u'\n')
130
131 return
132
133
135
136 vars = {}
137 xpath_ctx = XsltContext(node, processor=key_handler,
138 processorNss=NSS, varBindings=vars,
139 currentNode=node
140 )
141 xpath_ctx.currentInstruction = faux_instruction()
142 xpath_ctx.functions = FUNCTIONS
143 expr = CompileXPath(u'xhtml:div')
144 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
145 WRITER.text(u'Assertion failure:\n')
146 WRITER.text(u'An atom:content of type="xhtml" must have a direct\n xhtml:div child element. (RFC 4287, sec.4.1.3)')
147 WRITER.text(u'\n')
148 WRITER.text(u'\n')
149
150 return
151
152
154
155 vars = {}
156 xpath_ctx = XsltContext(node, processor=key_handler,
157 processorNss=NSS, varBindings=vars,
158 currentNode=node
159 )
160 xpath_ctx.currentInstruction = faux_instruction()
161 xpath_ctx.functions = FUNCTIONS
162 expr = CompileXPath(u'xhtml:div')
163 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
164 WRITER.text(u'Assertion failure:\n')
165 WRITER.text(u'An atom:rights of type="xhtml" must have a direct xhtml:div\n child element (RFC 4287, sec.4.1.10)')
166 WRITER.text(u'\n')
167 WRITER.text(u'\n')
168
169 return
170
171
173
174 vars = {}
175 xpath_ctx = XsltContext(node, processor=key_handler,
176 processorNss=NSS, varBindings=vars,
177 currentNode=node
178 )
179 xpath_ctx.currentInstruction = faux_instruction()
180 xpath_ctx.functions = FUNCTIONS
181 expr = CompileXPath(u'xhtml:div')
182 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
183 WRITER.text(u'Assertion failure:\n')
184 WRITER.text(u'An atom:title of type="xhtml" must have a direct xhtml:div\n child element (RFC 4287, sec.4.1.14)')
185 WRITER.text(u'\n')
186 WRITER.text(u'\n')
187
188 return
189
190
192
193 vars = {}
194 xpath_ctx = XsltContext(node, processor=key_handler,
195 processorNss=NSS, varBindings=vars,
196 currentNode=node
197 )
198 xpath_ctx.currentInstruction = faux_instruction()
199 xpath_ctx.functions = FUNCTIONS
200 expr = CompileXPath(u'xhtml:div')
201 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
202 WRITER.text(u'Assertion failure:\n')
203 WRITER.text(u'An atom:subtitle of type="xhtml" must have a direct\n xhtml:div child element (RFC 4287, sec.4.1.12)')
204 WRITER.text(u'\n')
205 WRITER.text(u'\n')
206
207 return
208
209
211
212 vars = {}
213 xpath_ctx = XsltContext(node, processor=key_handler,
214 processorNss=NSS, varBindings=vars,
215 currentNode=node
216 )
217 xpath_ctx.currentInstruction = faux_instruction()
218 xpath_ctx.functions = FUNCTIONS
219 expr = CompileXPath(u'xhtml:div')
220 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
221 WRITER.text(u'Assertion failure:\n')
222 WRITER.text(u'An atom:summary of type="xhtml" must have a direct\n xhtml:div child element (RFC 4287, sec.4.1.13)')
223 WRITER.text(u'\n')
224 WRITER.text(u'\n')
225
226 return
227
228
230
231 vars = {}
232 xpath_ctx = XsltContext(node, processor=key_handler,
233 processorNss=NSS, varBindings=vars,
234 currentNode=node
235 )
236 xpath_ctx.currentInstruction = faux_instruction()
237 xpath_ctx.functions = FUNCTIONS
238 expr = CompileXPath(u'count(atom:id) = 1')
239 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
240 WRITER.text(u'Assertion failure:\n')
241 WRITER.text(u'An atom entry must have one and only one atom:id\n element. (RFC 4287, sec.4.1.2)')
242 WRITER.text(u'\n')
243 WRITER.text(u'\n')
244 expr = CompileXPath(u'count(atom:title) = 1')
245 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
246 WRITER.text(u'Assertion failure:\n')
247 WRITER.text(u'An atom entry must have one and only one\n atom:title element. (RFC 4287, sec.4.1.2)')
248 WRITER.text(u'\n')
249 WRITER.text(u'\n')
250 expr = CompileXPath(u'count(atom:updated) = 1')
251 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
252 WRITER.text(u'Assertion failure:\n')
253 WRITER.text(u'An atom entry must have one and only one\n atom:updated element. (RFC 4287, sec.4.1.2)')
254 WRITER.text(u'\n')
255 WRITER.text(u'\n')
256 expr = CompileXPath(u'count(atom:content) <= 1')
257 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
258 WRITER.text(u'Assertion failure:\n')
259 WRITER.text(u'An atom entry cannot have more than\n one atom:content element. (RFC 4287, sec.4.1.2)')
260 WRITER.text(u'\n')
261 WRITER.text(u'\n')
262 expr = CompileXPath(u'count(atom:published) <= 1')
263 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
264 WRITER.text(u'Assertion failure:\n')
265 WRITER.text(u'An atom entry cannot have more than\n one atom:published element. (RFC 4287, sec.4.1.2)')
266 WRITER.text(u'\n')
267 WRITER.text(u'\n')
268 expr = CompileXPath(u'count(atom:source) <= 1')
269 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
270 WRITER.text(u'Assertion failure:\n')
271 WRITER.text(u'An atom entry cannot have more than\n one atom:source element. (RFC 4287, sec.4.1.2)')
272 WRITER.text(u'\n')
273 WRITER.text(u'\n')
274 expr = CompileXPath(u'count(atom:rights) <= 1')
275 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
276 WRITER.text(u'Assertion failure:\n')
277 WRITER.text(u'An atom entry cannot have more than\n one atom:rights element. (RFC 4287, sec.4.1.2)')
278 WRITER.text(u'\n')
279 WRITER.text(u'\n')
280 expr = CompileXPath(u'count(atom:summary) <= 1')
281 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
282 WRITER.text(u'Assertion failure:\n')
283 WRITER.text(u'An atom entry cannot have more than\n one atom:summary element.')
284 WRITER.text(u'\n')
285 WRITER.text(u'\n')
286 expr = CompileXPath(u'not(atom:subtitle)')
287 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
288 WRITER.text(u'Assertion failure:\n')
289 WRITER.text(u'An atom entry cannot have an atom:subtitle\n element. (RFC 4287, sec.4.1.2)')
290 WRITER.text(u'\n')
291 WRITER.text(u'\n')
292
293 return
294
295
297
298 vars = {}
299 xpath_ctx = XsltContext(node, processor=key_handler,
300 processorNss=NSS, varBindings=vars,
301 currentNode=node
302 )
303 xpath_ctx.currentInstruction = faux_instruction()
304 xpath_ctx.functions = FUNCTIONS
305 expr = CompileXPath(u'count(atom:name) = 1')
306 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
307 WRITER.text(u'Assertion failure:\n')
308 WRITER.text(u'An atom:author element must have one and only\n one atom:name element. (RFC 4287, sec.3.2)')
309 WRITER.text(u'\n')
310 WRITER.text(u'\n')
311 expr = CompileXPath(u'count(atom:uri) <= 1')
312 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
313 WRITER.text(u'Assertion failure:\n')
314 WRITER.text(u'An atom:author element cannot have more\n than one atom:uri element. (RFC 4287, sec.3.2)')
315 WRITER.text(u'\n')
316 WRITER.text(u'\n')
317 expr = CompileXPath(u'count(atom:email) <= 1')
318 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
319 WRITER.text(u'Assertion failure:\n')
320 WRITER.text(u'An atom:author element cannot have more\n than one atom:email element. (RFC 4287, sec.3.2)')
321 WRITER.text(u'\n')
322 WRITER.text(u'\n')
323
324 return
325
326
328
329 vars = {}
330 xpath_ctx = XsltContext(node, processor=key_handler,
331 processorNss=NSS, varBindings=vars,
332 currentNode=node
333 )
334 xpath_ctx.currentInstruction = faux_instruction()
335 xpath_ctx.functions = FUNCTIONS
336 expr = CompileXPath(u'count(atom:name) = 1')
337 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
338 WRITER.text(u'Assertion failure:\n')
339 WRITER.text(u'An atom:contributor element must have one and\n only one atom:name element. (RFC 4287, sec.3.2)')
340 WRITER.text(u'\n')
341 WRITER.text(u'\n')
342 expr = CompileXPath(u'count(atom:uri) <= 1')
343 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
344 WRITER.text(u'Assertion failure:\n')
345 WRITER.text(u'An atom:contributor element cannot have\n more than one atom:uri element. (RFC 4287, sec.3.2)')
346 WRITER.text(u'\n')
347 WRITER.text(u'\n')
348 expr = CompileXPath(u'count(atom:email) <= 1')
349 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
350 WRITER.text(u'Assertion failure:\n')
351 WRITER.text(u'An atom:contributor element cannot have\n more than one atom:email element. (RFC 4287, sec.3.2)')
352 WRITER.text(u'\n')
353 WRITER.text(u'\n')
354
355 return
356
357
359
360 vars = {}
361 xpath_ctx = XsltContext(node, processor=key_handler,
362 processorNss=NSS, varBindings=vars,
363 currentNode=node
364 )
365 xpath_ctx.currentInstruction = faux_instruction()
366 xpath_ctx.functions = FUNCTIONS
367 expr = CompileXPath(u'@href')
368 if not Conversions.BooleanValue(expr.evaluate(xpath_ctx)):
369 WRITER.text(u'Assertion failure:\n')
370 WRITER.text(u'An atom:link must have one and only one href attribute. (RFC\n 4287, sec.4.2.7)')
371 WRITER.text(u'\n')
372 WRITER.text(u'\n')
373
374 return
375
376
378
379 vars = {}
380 xpath_ctx = XsltContext(node, processor=key_handler,
381 processorNss=NSS, varBindings=vars,