• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python -u
2import libxml2
3
4try:
5    import libxml2mod
6except ModuleNotFoundError:
7    from libxmlmods import libxml2mod
8
9import sys
10
11def error(msg, data):
12    pass
13
14# Memory debug specific
15libxml2.debugMemory(1)
16
17dtd="""<!ELEMENT foo EMPTY>"""
18instance="""<?xml version="1.0"?>
19<foo></foo>"""
20
21dtd = libxml2.parseDTD(None, 'test.dtd')
22ctxt = libxml2.newValidCtxt()
23libxml2mod.xmlSetValidErrors(ctxt._o, error, error)
24doc = libxml2.parseDoc(instance)
25ret = doc.validateDtd(ctxt, dtd)
26if ret != 1:
27    print("error doing DTD validation")
28    sys.exit(1)
29
30doc.freeDoc()
31dtd.freeDtd()
32del dtd
33del ctxt
34
35# Memory debug specific
36libxml2.cleanupParser()
37if libxml2.debugMemory(1) == 0:
38    print("OK")
39else:
40    print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
41    libxml2.dumpMemory()
42