VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/readererr.py@ 105420

Last change on this file since 105420 was 105420, checked in by vboxsync, 7 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/env python3
2#
3# this tests the basic APIs of the XmlTextReader interface
4#
5import setup_test
6import libxml2
7import sys
8try:
9 import StringIO
10 str_io = StringIO.StringIO
11except:
12 import io
13 str_io = io.StringIO
14
15# Memory debug specific
16libxml2.debugMemory(1)
17
18expect="""--> (3) test1:1:xmlns: URI foo is not absolute
19--> (4) test1:1:Opening and ending tag mismatch: c line 1 and a
20"""
21err=""
22def myErrorHandler(arg,msg,severity,locator):
23 global err
24 err = err + "%s (%d) %s:%d:%s" % (arg,severity,locator.BaseURI(),locator.LineNumber(),msg)
25
26f = str_io("""<a xmlns="foo"><b b1="b1"/><c>content of c</a>""")
27input = libxml2.inputBuffer(f)
28reader = input.newTextReader("test1")
29reader.SetErrorHandler(myErrorHandler,"-->")
30while reader.Read() == 1:
31 pass
32
33if err != expect:
34 print("error")
35 print("received %s" %(err))
36 print("expected %s" %(expect))
37 sys.exit(1)
38
39reader.SetErrorHandler(None,None)
40if reader.GetErrorHandler() != (None,None):
41 print("GetErrorHandler failed")
42 sys.exit(1)
43
44#
45# cleanup for memory allocation counting
46#
47del f
48del input
49del reader
50
51# Memory debug specific
52libxml2.cleanupParser()
53if libxml2.debugMemory(1) == 0:
54 print("OK")
55else:
56 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette