ยปCore Development>Code coverage>Doc/includes/minidom-example.py

Python code coverage for Doc/includes/minidom-example.py

#countcontent
1n/aimport xml.dom.minidom
2n/a
3n/adocument = """\
4n/a<slideshow>
5n/a<title>Demo slideshow</title>
6n/a<slide><title>Slide title</title>
7n/a<point>This is a demo</point>
8n/a<point>Of a program for processing slides</point>
9n/a</slide>
10n/a
11n/a<slide><title>Another demo slide</title>
12n/a<point>It is important</point>
13n/a<point>To have more than</point>
14n/a<point>one slide</point>
15n/a</slide>
16n/a</slideshow>
17n/a"""
18n/a
19n/adom = xml.dom.minidom.parseString(document)
20n/a
21n/adef getText(nodelist):
22n/a rc = []
23n/a for node in nodelist:
24n/a if node.nodeType == node.TEXT_NODE:
25n/a rc.append(node.data)
26n/a return ''.join(rc)
27n/a
28n/adef handleSlideshow(slideshow):
29n/a print("<html>")
30n/a handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
31n/a slides = slideshow.getElementsByTagName("slide")
32n/a handleToc(slides)
33n/a handleSlides(slides)
34n/a print("</html>")
35n/a
36n/adef handleSlides(slides):
37n/a for slide in slides:
38n/a handleSlide(slide)
39n/a
40n/adef handleSlide(slide):
41n/a handleSlideTitle(slide.getElementsByTagName("title")[0])
42n/a handlePoints(slide.getElementsByTagName("point"))
43n/a
44n/adef handleSlideshowTitle(title):
45n/a print("<title>%s</title>" % getText(title.childNodes))
46n/a
47n/adef handleSlideTitle(title):
48n/a print("<h2>%s</h2>" % getText(title.childNodes))
49n/a
50n/adef handlePoints(points):
51n/a print("<ul>")
52n/a for point in points:
53n/a handlePoint(point)
54n/a print("</ul>")
55n/a
56n/adef handlePoint(point):
57n/a print("<li>%s</li>" % getText(point.childNodes))
58n/a
59n/adef handleToc(slides):
60n/a for slide in slides:
61n/a title = slide.getElementsByTagName("title")[0]
62n/a print("<p>%s</p>" % getText(title.childNodes))
63n/a
64n/ahandleSlideshow(dom)