MCPcopy
hub / github.com/rocky/python-uncompyle6 / escape_string

Function escape_string

uncompyle6/semantics/helper.py:29–44  ·  view source on GitHub ↗
(s, quotes=('"', "'", '"""', "'''"))

Source from the content-addressed store, hash-verified

27nonglobal_ops = frozenset(('STORE_DEREF', 'DELETE_DEREF'))
28
29def escape_string(s, quotes=('"', "'", '"""', "'''")):
30 quote = None
31 for q in quotes:
32 if s.find(q) == -1:
33 quote = q
34 break
35 pass
36 if quote is None:
37 quote = '"""'
38 s = s.replace('"""', '\\"""')
39
40 for (orig, replace) in (('\t', '\\t'),
41 ('\n', '\\n'),
42 ('\r', '\\r')):
43 s = s.replace(orig, replace)
44 return "%s%s%s" % (quote, s, quote)
45
46# FIXME: this and find_globals could be parameterized with one of the
47# above global ops

Callers 5

n_formatted_valueFunction · 0.90
n_formatted_value1Function · 0.90
n_formatted_value2Function · 0.90
n_joined_strFunction · 0.90
n_formatted_value_debugFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected