VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.4/python/tests/readererr.py@ 76389

最後變更 在這個檔案從76389是 65950,由 vboxsync 提交於 8 年 前

libxml 2.9.4: fix export

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

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