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

Function escape

Lib/xml/sax/saxutils.py:18–32  ·  view source on GitHub ↗

Escape &, <, and > in a string of data. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value.

(data, entities={})

Source from the content-addressed store, hash-verified

16 return s
17
18def escape(data, entities={}):
19 """Escape &, <, and > in a string of data.
20
21 You can escape other strings of data by passing a dictionary as
22 the optional entities parameter. The keys and values must all be
23 strings; each key will be replaced with its corresponding value.
24 """
25
26 # must do ampersand first
27 data = data.replace("&", "&amp;")
28 data = data.replace(">", "&gt;")
29 data = data.replace("<", "&lt;")
30 if entities:
31 data = __dict_replace(data, entities)
32 return data
33
34def unescape(data, entities={}):
35 """Unescape &amp;, &lt;, and &gt; in a string of data.

Callers 5

test_escape_basicMethod · 0.90
test_escape_allMethod · 0.90
test_escape_extraMethod · 0.90
quoteattrFunction · 0.70
charactersMethod · 0.70

Calls 2

__dict_replaceFunction · 0.85
replaceMethod · 0.45

Tested by 3

test_escape_basicMethod · 0.72
test_escape_allMethod · 0.72
test_escape_extraMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…