source: exist/trunk/python/elementtree-1.3a6-20070220-badc/unittests/support.py @ 3578

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/elementtree-1.3a6-20070220-badc/unittests/support.py@3578
Revision 3578, 1.1 KB checked in by pjkersha, 11 years ago (diff)

Latest releases from Fredrik Lundh. 10 March release has exclusive C14N support with namespace prefixes.

Line 
1# $Id: support.py 3356 2008-01-14 18:56:25Z fredrik $
2
3import elementtree.ElementTree as ET
4
5import sys, os
6
7def note(text):
8    print >>sys.stderr, text
9
10def serialize(elem, **options):
11    import StringIO
12    file = StringIO.StringIO()
13    tree = ET.ElementTree(elem)
14    tree.write(file, **options)
15    return file.getvalue()
16
17def summarize(elem):
18    tag = elem.tag
19    if elem.get("id"):
20        tag = tag + "#" + elem.get("id")
21    return tag
22
23def summarize_list(seq):
24    return map(summarize, seq)
25
26def normalize_crlf(tree):
27    for elem in tree.iter():
28        if elem.text: elem.text = elem.text.replace("\r\n", "\n")
29        if elem.tail: elem.tail = elem.tail.replace("\r\n", "\n")
30
31SAMPLE_XML = ET.XML("""
32<body>
33  <tag class='a' id='1'>text</tag>
34  <tag class='b' id='2' />
35  <section>
36    <tag class='b' id='inner' href='foo'>subtext</tag>
37  </section>
38</body>
39""")
40
41SAMPLE_XML_NS = ET.XML("""
42<body xmlns='ns'>
43  <tag class='a' id='1'>text</tag>
44  <tag class='b' id='2' />
45  <section>
46    <tag class='b' id='inner' href='foo'>subtext</tag>
47  </section>
48</body>
49""")
Note: See TracBrowser for help on using the repository browser.