2 # -*- coding: ISO-8859-1 -*-
6 # Memory debug specific
12 def __init__(self, startd, starte, ende, delta, endd):
20 def startDocument(self):
22 if ctxt.byteConsumed() != self.startd:
23 print("document start at wrong index: %d expecting %d\n" % (
24 ctxt.byteConsumed(), self.startd))
27 def endDocument(self):
29 expect = self.ende + self.delta * (self.count - 1) + self.endd
30 if ctxt.byteConsumed() != expect:
31 print("document end at wrong index: %d expecting %d\n" % (
32 ctxt.byteConsumed(), expect))
35 def startElement(self, tag, attrs):
38 expect = self.starte + self.delta * self.count
39 if ctxt.byteConsumed() != expect:
40 print("element start at wrong index: %d expecting %d\n" % (
41 ctxt.byteConsumed(), expect))
45 def endElement(self, tag):
48 expect = self.ende + self.delta * self.count
49 if ctxt.byteConsumed() != expect:
50 print("element end at wrong index: %d expecting %d\n" % (
51 ctxt.byteConsumed(), expect))
53 self.count = self.count + 1
55 def characters(self, data):
59 # First run a pure UTF-8 test
61 handler = callback(0, 13, 27, 198, 183)
62 ctxt = libxml2.createPushParser(handler, "<foo>\n", 6, "test.xml")
63 chunk = """ <bar1>chars1</bar1>
75 ctxt.parseChunk(chunk, len(chunk), 0)
78 ctxt.parseChunk(chunk, len(chunk), 1)
82 # Then run a test relying on ISO-Latin-1
84 handler = callback(43, 57, 71, 198, 183)
85 chunk="""<?xml version="1.0" encoding="ISO-8859-1"?>
88 ctxt = libxml2.createPushParser(handler, chunk, len(chunk), "test.xml")
89 chunk = """ <bar1>chars1</bar1>
101 ctxt.parseChunk(chunk, len(chunk), 0)
104 ctxt.parseChunk(chunk, len(chunk), 1)
107 # Memory debug specific
108 libxml2.cleanupParser()
109 if libxml2.debugMemory(1) == 0:
112 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))