2 import string
, sys
, time
4 from threading
import Thread
, Lock
18 def handler(self
,ctx
,str):
20 self
.errors
.append(str)
23 def getLineNumbersDefault():
24 old
= libxml2
.lineNumbersDefault(0)
25 libxml2
.lineNumbersDefault(old
)
28 def test(expectedLineNumbersDefault
):
31 # check a per thread-global
32 if expectedLineNumbersDefault
!= getLineNumbersDefault():
34 print "FAILED to obtain correct value for " \
35 "lineNumbersDefault in thread %d" % thread
.get_ident()
36 # check ther global error handler
37 # (which is NOT per-thread in the python bindings)
39 doc
= libxml2
.parseFile("bad.xml")
45 # global error handler
47 libxml2
.registerErrorHandler(eh
.handler
,"")
49 # set on the main thread only
50 libxml2
.lineNumbersDefault(1)
54 print "FAILED: should have obtained errors"
58 for i
in range(THREADS_COUNT
):
59 # expect 0 for lineNumbersDefault because
60 # the new value has been set on the main thread only
61 ts
.append(Thread(target
=test
,args
=(0,)))
67 if len(eh
.errors
) != ec
+THREADS_COUNT
*ec
:
68 print "FAILED: did not obtain the correct number of errors"
71 # set lineNumbersDefault for future new threads
72 libxml2
.thrDefLineNumbersDefaultValue(1)
74 for i
in range(THREADS_COUNT
):
75 # expect 1 for lineNumbersDefault
76 ts
.append(Thread(target
=test
,args
=(1,)))
82 if len(eh
.errors
) != ec
+THREADS_COUNT
*ec
*2:
83 print "FAILED: did not obtain the correct number of errors"
90 # Memory debug specific
91 libxml2
.cleanupParser()
92 if libxml2
.debugMemory(1) == 0:
95 print "Memory leak %d bytes" % (libxml2
.debugMemory(1))