tstURI.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python -u
  2. import sys
  3. import libxml2
  4. # Memory debug specific
  5. libxml2.debugMemory(1)
  6. uri = libxml2.parseURI("http://example.org:8088/foo/bar?query=simple#fragid")
  7. if uri.scheme() != 'http':
  8. print "Error parsing URI: wrong scheme"
  9. sys.exit(1)
  10. if uri.server() != 'example.org':
  11. print "Error parsing URI: wrong server"
  12. sys.exit(1)
  13. if uri.port() != 8088:
  14. print "Error parsing URI: wrong port"
  15. sys.exit(1)
  16. if uri.path() != '/foo/bar':
  17. print "Error parsing URI: wrong path"
  18. sys.exit(1)
  19. if uri.query() != 'query=simple':
  20. print "Error parsing URI: wrong query"
  21. sys.exit(1)
  22. if uri.fragment() != 'fragid':
  23. print "Error parsing URI: wrong query"
  24. sys.exit(1)
  25. uri.setScheme("https")
  26. uri.setPort(223)
  27. uri.setFragment(None)
  28. result=uri.saveUri()
  29. if result != "https://example.org:223/foo/bar?query=simple":
  30. print "Error modifying or saving the URI"
  31. uri = None
  32. # Memory debug specific
  33. libxml2.cleanupParser()
  34. if libxml2.debugMemory(1) == 0:
  35. print "OK"
  36. else:
  37. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  38. libxml2.dumpMemory()