File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 13
13
import operator
14
14
import pickle
15
15
import sys
16
+ import textwrap
16
17
import types
17
18
import unittest
18
19
import warnings
@@ -715,6 +716,27 @@ def end_ns(self, prefix):
715
716
('end-ns' , '' ),
716
717
])
717
718
719
+ def test_custom_builder_only_end_ns (self ):
720
+ class Builder (list ):
721
+ def end_ns (self , prefix ):
722
+ self .append (("end-ns" , prefix ))
723
+
724
+ builder = Builder ()
725
+ parser = ET .XMLParser (target = builder )
726
+ parser .feed (textwrap .dedent ("""\
727
+ <?pi data?>
728
+ <!-- comment -->
729
+ <root xmlns='namespace' xmlns:p='pns' xmlns:a='ans'>
730
+ <a:element key='value'>text</a:element>
731
+ <p:element>text</p:element>tail
732
+ <empty-element/>
733
+ </root>
734
+ """ ))
735
+ self .assertEqual (builder , [
736
+ ('end-ns' , 'a' ),
737
+ ('end-ns' , 'p' ),
738
+ ('end-ns' , '' ),
739
+ ])
718
740
719
741
# Element.getchildren() and ElementTree.getiterator() are deprecated.
720
742
@checkwarnings (("This method will be removed in future versions. "
You can’t perform that action at this time.
0 commit comments