VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.31/python/tests/readererr.py@ 55391

最後變更 在這個檔案從55391是 39915,由 vboxsync 提交於 13 年 前

libxml-2.6.31 unmodified

  • 屬性 svn:eol-style 設為 native
檔案大小: 1.2 KB
 
1#!/usr/bin/python -u
2#
3# this tests the basic APIs of the XmlTextReader interface
4#
5import libxml2
6import StringIO
7import sys
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12expect="""--> (3) test1:1:xmlns: URI foo is not absolute
13--> (4) test1:1:Opening and ending tag mismatch: c line 0 and a
14"""
15err=""
16def myErrorHandler(arg,msg,severity,locator):
17 global err
18 err = err + "%s (%d) %s:%d:%s" % (arg,severity,locator.BaseURI(),locator.LineNumber(),msg)
19
20f = StringIO.StringIO("""<a xmlns="foo"><b b1="b1"/><c>content of c</a>""")
21input = libxml2.inputBuffer(f)
22reader = input.newTextReader("test1")
23reader.SetErrorHandler(myErrorHandler,"-->")
24while reader.Read() == 1:
25 pass
26
27if err != expect:
28 print "error"
29 print "received %s" %(err)
30 print "expected %s" %(expect)
31 sys.exit(1)
32
33reader.SetErrorHandler(None,None)
34if reader.GetErrorHandler() != (None,None):
35 print "GetErrorHandler failed"
36 sys.exit(1)
37
38#
39# cleanup for memory allocation counting
40#
41del f
42del input
43del reader
44
45# Memory debug specific
46libxml2.cleanupParser()
47if libxml2.debugMemory(1) == 0:
48 print "OK"
49else:
50 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
51 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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