def test(): data = sys.stdin.read() doc = Sax2.FromXml(data) b1 = doc.createElementNS("http://foo.com", "foo:branch") c1 = doc.createElementNS("http://foo.com", "foo:child1") c2 = doc.createElementNS("http://foo.com", "foo:child2") b1.setAttributeNS("http://foo.com", "foo:a1", "value-1") a1 = b1.getAttributeNodeNS("http://foo.com", "a1") a1.value = "This shouldn't leak" b1.appendChild(c1) b1.appendChild(c2) doc.documentElement.appendChild(b1) r1 = doc.createElementNS("http://foo.com", "foo:replace") doc.documentElement.replaceChild(r1, b1) b1.removeChild(c2) import cStringIO s = cStringIO.StringIO() import xml.dom.ext xml.dom.ext.Print(doc, stream=s) ext.ReleaseNode(doc) ext.ReleaseNode(b1) doc = Sax2.FromXml(data) ext.ReleaseNode(doc)
def Test(tester): tester.startGroup("Alexander Fayolle's encoding problems and variations") tester.startTest('XML output UTF-8 encoding') d = Sax2.FromXml(source_1) stream = cStringIO.StringIO() Print(d, stream=stream) result = stream.getvalue() if result != expected_1: tester.error('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_1), repr(result))) tester.testDone() tester.startTest('XML output ISO-8859-1 encoding') d = Sax2.FromXml(source_1) stream = cStringIO.StringIO() Print(d, stream=stream, encoding='ISO-8859-1') result = stream.getvalue() if result != expected_2: tester.error('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_2), repr(result))) tester.testDone() return tester.groupDone()
def test(tester): tester.startGroup('XML With Namespaces') tester.startTest('Namespaces multiply defined at 2nd level') from xml.dom.ext.reader import Sax2 import xml.dom.ext doc = Sax2.FromXml(source_1) xml.dom.ext.Print(doc) tester.testDone() return tester.groupDone()
def Test(tester): tester.startGroup("Alexander Fayolle's Problems and variations") tester.startTest('Bad setAttNS test') d = Sax2.FromXml('<doc/>') e = d.createElementNS('', 'elt') d.documentElement.appendChild(e) try: e.setAttributeNS('http://logilab', 'att', 'value1') except DOMException, x: if x.code != NAMESPACE_ERR: name = getExceptionName(x.code) tester.error("Wrong exception '%s', expected NAMESPACE_ERR" % name)
def Test(tester): tester.startGroup( "Nicolas Chauvat <*****@*****.**>'s Printer Bug Report") tester.startTest('Attribute quote print') d = Sax2.FromXml(source_1) stream = cStringIO.StringIO() Print(d, stream=stream) result = stream.getvalue() if result != expected_1: tester.error('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_1), repr(result))) return tester.groupDone()
def get_vm_infos(name): global vm_list global gmetric ret = '' c = 0 cpuinfos = '' meminfos = '' diskinfos = '' netinfos = '' vminfos = '' sep = '' for i in vm_list: cmd = 'virsh dumpxml ' + i[0] (stat, domxml) = commands.getstatusoutput(cmd) doc = Sax2.FromXml(domxml) c += 1 if c > 1: sep = '|' prefix = sep + "vmName:" + i[1] + ";" cpuinfos += prefix + get_vm_cpuinfos(doc, i[0]) meminfos += prefix + get_vm_meminfos(doc, i[0]) diskinfos += prefix + get_vm_diskinfos(doc, i[0]) netinfos += prefix + get_vm_netinfos(doc, i[0]) vminfos += sep + i[1] + ':' + i[2] if c >= 0: cmd = gmetric + ' -n "vm_cpu_infos" -v "' + cpuinfos + '"' #print cmd (stat, output) = commands.getstatusoutput(cmd) cmd = gmetric + ' -n "vm_mem_infos" -v "' + meminfos + '"' #print cmd (stat, output) = commands.getstatusoutput(cmd) cmd = gmetric + ' -n "vm_disk_infos" -v "' + diskinfos + '"' #print cmd #print len(cmd) (stat, output) = commands.getstatusoutput(cmd) cmd = gmetric + ' -n "vm_net_infos" -v "' + netinfos + '"' #print cmd (stat, output) = commands.getstatusoutput(cmd) cmd = gmetric + ' -n "vm_name_infos" -v "' + vminfos + '"' #print cmd #print len(cmd) (stat, output) = commands.getstatusoutput(cmd) return c # ret # Ganglia python module's string length limited
def __init__(my, pipeline_xml): if IMPORT_ERROR: print IMPORT_ERROR return my.doc = Sax2.FromXml(pipeline_xml)
def __init__(self, pipeline_xml): if IMPORT_ERROR: print IMPORT_ERROR return self.doc = Sax2.FromXml(pipeline_xml)
def load(self, fh): return thing_from_dom(Sax2.FromXml(fh.read(), validate=0))
Print(d, stream=stream) result = stream.getvalue() if result != expected_1: tester.error('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_1), repr(result))) stream = cStringIO.StringIO() PrettyPrint(d, stream=stream) result = stream.getvalue() if result != expected_2: tester.error('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_2), repr(result))) tester.testDone() tester.startTest('Document Fragment Printing') d = Sax2.FromXml(source_1) df = d.createDocumentFragment() for n in d.documentElement.childNodes: df.appendChild(n.cloneNode(1)) if len(df.childNodes) != len(d.documentElement.childNodes): tester.error('Docfrag append error') if df.childNodes.length != d.documentElement.childNodes.length: tester.error('Docfrag append error') stream = cStringIO.StringIO() PrettyPrint(df, stream=stream) result = stream.getvalue() if result != expected_3: raise Exception('Expected\n"""%s"""\ngot\n"""%s"""' % (repr(expected_3), repr(result))) tester.testDone()