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

10 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-02-28 09:09 +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")