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

Function _serialize_html

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

Source from the content-addressed store, hash-verified

912 "track", "wbr"}
913
914def _serialize_html(write, elem, qnames, namespaces, **kwargs):
915 tag = elem.tag
916 text = elem.text
917 if tag is Comment:
918 write("<!--%s-->" % _escape_cdata(text))
919 elif tag is ProcessingInstruction:
920 write("<?%s?>" % _escape_cdata(text))
921 else:
922 tag = qnames[tag]
923 if tag is None:
924 if text:
925 write(_escape_cdata(text))
926 for e in elem:
927 _serialize_html(write, e, qnames, None)
928 else:
929 write("<" + tag)
930 items = list(elem.items())
931 if items or namespaces:
932 if namespaces:
933 for v, k in sorted(namespaces.items(),
934 key=lambda x: x[1]): # sort on prefix
935 if k:
936 k = ":" + k
937 write(" xmlns%s=\"%s\"" % (
938 k,
939 _escape_attrib(v)
940 ))
941 for k, v in items:
942 if isinstance(k, QName):
943 k = k.text
944 if isinstance(v, QName):
945 v = qnames[v.text]
946 else:
947 v = _escape_attrib_html(v)
948 # FIXME: handle boolean attributes
949 write(" %s=\"%s\"" % (qnames[k], v))
950 write(">")
951 ltag = tag.lower()
952 if text:
953 if ltag == "script" or ltag == "style":
954 write(text)
955 else:
956 write(_escape_cdata(text))
957 for e in elem:
958 _serialize_html(write, e, qnames, None)
959 if ltag not in HTML_EMPTY:
960 write("</" + tag + ">")
961 if elem.tail:
962 write(_escape_cdata(elem.tail))
963
964def _serialize_text(write, elem):
965 for part in elem.itertext():

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…