VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/pushSAX.py@ 106165

最後變更 在這個檔案從106165是 105420,由 vboxsync 提交於 4 月 前

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

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.5 KB
 
1#!/usr/bin/env python3
2import sys
3import setup_test
4import libxml2
5
6# Memory debug specific
7libxml2.debugMemory(1)
8
9log = ""
10
11class callback:
12 def startDocument(self):
13 global log
14 log = log + "startDocument:"
15
16 def endDocument(self):
17 global log
18 log = log + "endDocument:"
19
20 def startElement(self, tag, attrs):
21 global log
22 log = log + "startElement %s %s:" % (tag, attrs)
23
24 def endElement(self, tag):
25 global log
26 log = log + "endElement %s:" % (tag)
27
28 def characters(self, data):
29 global log
30 log = log + "characters: %s:" % (data)
31
32 def warning(self, msg):
33 global log
34 log = log + "warning: %s:" % (msg)
35
36 def error(self, msg):
37 global log
38 log = log + "error: %s:" % (msg)
39
40 def fatalError(self, msg):
41 global log
42 log = log + "fatalError: %s:" % (msg)
43
44handler = callback()
45
46ctxt = libxml2.createPushParser(handler, "<foo", 4, "test.xml")
47chunk = " url='tst'>b"
48ctxt.parseChunk(chunk, len(chunk), 0)
49chunk = "ar</foo>"
50ctxt.parseChunk(chunk, len(chunk), 1)
51ctxt=None
52
53reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:"
54if log != reference:
55 print("Error got: %s" % log)
56 print("Exprected: %s" % reference)
57 sys.exit(1)
58
59# Memory debug specific
60libxml2.cleanupParser()
61if libxml2.debugMemory(1) == 0:
62 print("OK")
63else:
64 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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