VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.4/python/tests/reader4.py@ 83604

最後變更 在這個檔案從83604是 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
17def tst_reader(s):
18 f = str_io(s)
19 input = libxml2.inputBuffer(f)
20 reader = input.newTextReader("tst")
21 res = ""
22 while reader.Read():
23 res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
24 reader.Value(), reader.IsEmptyElement())
25 if reader.NodeType() == 1: # Element
26 while reader.MoveToNextAttribute():
27 res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
28 reader.Name(),reader.Value())
29 return res
30
31expect="""1 (test) [None] 0
321 (b) [None] 1
331 (c) [None] 1
3415 (test) [None] 0
35"""
36
37res = tst_reader("""<test><b/><c/></test>""")
38
39if res != expect:
40 print("Did not get the expected error message:")
41 print(res)
42 sys.exit(1)
43
44# Memory debug specific
45libxml2.cleanupParser()
46if libxml2.debugMemory(1) == 0:
47 print("OK")
48else:
49 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
50 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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