Coverage for src/ptf/solr/xmlutils.py: 0%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-05 09:56 +0000

1from lxml import etree 

2 

3 

4def escape(s): 

5 return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;") 

6 

7 

8def innerxml(node, mixed=True): 

9 # traiter & 

10 if mixed: 

11 if node.text: 

12 parts = [escape(node.text)] + [ 

13 etree.tostring(c, encoding="unicode") for c in node.getchildren() 

14 ] 

15 else: 

16 parts = [etree.tostring(c, encoding="unicode") for c in node.getchildren()] 

17 else: 

18 parts = [ 

19 etree.tostring(c, encoding="unicode", with_tail=False) for c in node.getchildren() 

20 ] 

21 return "".join(parts).strip().encode("utf-8")