resolver.py 777 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python -u
  2. import sys
  3. import libxml2
  4. import StringIO
  5. # Memory debug specific
  6. libxml2.debugMemory(1)
  7. def myResolver(URL, ID, ctxt):
  8. return(StringIO.StringIO("<foo/>"))
  9. libxml2.setEntityLoader(myResolver)
  10. doc = libxml2.parseFile("doesnotexist.xml")
  11. root = doc.children
  12. if root.name != "foo":
  13. print "root element name error"
  14. sys.exit(1)
  15. doc.freeDoc()
  16. i = 0
  17. while i < 5000:
  18. doc = libxml2.parseFile("doesnotexist.xml")
  19. root = doc.children
  20. if root.name != "foo":
  21. print "root element name error"
  22. sys.exit(1)
  23. doc.freeDoc()
  24. i = i + 1
  25. # Memory debug specific
  26. libxml2.cleanupParser()
  27. if libxml2.debugMemory(1) == 0:
  28. print "OK"
  29. else:
  30. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  31. libxml2.dumpMemory()