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

Function _escape_attrib

Lib/xml/etree/ElementTree.py:1034–1060  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

1032 _raise_serialization_error(text)
1033
1034def _escape_attrib(text):
1035 # escape attribute value
1036 try:
1037 if "&" in text:
1038 text = text.replace("&", "&")
1039 if "<" in text:
1040 text = text.replace("<", "&lt;")
1041 if ">" in text:
1042 text = text.replace(">", "&gt;")
1043 if "\"" in text:
1044 text = text.replace("\"", "&quot;")
1045 # Although section 2.11 of the XML specification states that CR or
1046 # CR LN should be replaced with just LN, it applies only to EOLNs
1047 # which take part of organizing file into lines. Within attributes,
1048 # we are replacing these with entity numbers, so they do not count.
1049 # http://www.w3.org/TR/REC-xml/#sec-line-ends
1050 # The current solution, contained in following six lines, was
1051 # discussed in issue 17582 and 39011.
1052 if "\r" in text:
1053 text = text.replace("\r", "&#13;")
1054 if "\n" in text:
1055 text = text.replace("\n", "&#10;")
1056 if "\t" in text:
1057 text = text.replace("\t", "&#09;")
1058 return text
1059 except (TypeError, AttributeError):
1060 _raise_serialization_error(text)
1061
1062def _escape_attrib_html(text):
1063 # escape attribute value

Callers 2

_serialize_xmlFunction · 0.85
_serialize_htmlFunction · 0.85

Calls 2

replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…