MCPcopy Index your code
hub / github.com/python/cpython / _serialize_xml

Function _serialize_xml

Lib/xml/etree/ElementTree.py:860–908  ·  view source on GitHub ↗
(write, elem, qnames, namespaces,
                   short_empty_elements, **kwargs)

Source from the content-addressed store, hash-verified

858 return qnames, namespaces
859
860def _serialize_xml(write, elem, qnames, namespaces,
861 short_empty_elements, **kwargs):
862 tag = elem.tag
863 text = elem.text
864 if tag is Comment:
865 write("<!--%s-->" % text)
866 elif tag is ProcessingInstruction:
867 write("<?%s?>" % text)
868 else:
869 tag = qnames[tag]
870 if tag is None:
871 if text:
872 write(_escape_cdata(text))
873 for e in elem:
874 _serialize_xml(write, e, qnames, None,
875 short_empty_elements=short_empty_elements)
876 else:
877 write("<" + tag)
878 items = list(elem.items())
879 if items or namespaces:
880 if namespaces:
881 for v, k in sorted(namespaces.items(),
882 key=lambda x: x[1]): # sort on prefix
883 if k:
884 k = ":" + k
885 write(" xmlns%s=\"%s\"" % (
886 k,
887 _escape_attrib(v)
888 ))
889 for k, v in items:
890 if isinstance(k, QName):
891 k = k.text
892 if isinstance(v, QName):
893 v = qnames[v.text]
894 else:
895 v = _escape_attrib(v)
896 write(" %s=\"%s\"" % (qnames[k], v))
897 if text or len(elem) or not short_empty_elements:
898 write(">")
899 if text:
900 write(_escape_cdata(text))
901 for e in elem:
902 _serialize_xml(write, e, qnames, None,
903 short_empty_elements=short_empty_elements)
904 write("</" + tag + ">")
905 else:
906 write(" />")
907 if elem.tail:
908 write(_escape_cdata(elem.tail))
909
910HTML_EMPTY = {"area", "base", "basefont", "br", "col", "embed", "frame", "hr",
911 "img", "input", "isindex", "link", "meta", "param", "source",

Callers

nothing calls this directly

Calls 5

_escape_cdataFunction · 0.85
listClass · 0.85
_escape_attribFunction · 0.85
writeFunction · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…