MCPcopy Create free account
hub / github.com/ElementsProject/elements / escape

Function escape

test/lint/lint-format-strings.py:72–84  ·  view source on GitHub ↗

Return the escaped version of string s with "\\\"", "\\n" and "\\t" escaped as "[escaped-backslash]", "[escaped-newline]" and "[escaped-tab]". >>> unescape(escape("foo")) == "foo" True >>> escape(r'foo \\t foo \\n foo \\\\ foo \\ foo \\"bar\\"') 'foo [escaped-tab] foo [escaped-n

(s)

Source from the content-addressed store, hash-verified

70
71
72def escape(s):
73 """Return the escaped version of string s with "\\\"", "\\n" and "\\t" escaped as
74 "[escaped-backslash]", "[escaped-newline]" and "[escaped-tab]".
75
76 >>> unescape(escape("foo")) == "foo"
77 True
78 >>> escape(r'foo \\t foo \\n foo \\\\ foo \\ foo \\"bar\\"')
79 'foo [escaped-tab] foo [escaped-newline] foo \\\\\\\\ foo \\\\ foo [escaped-quote]bar[escaped-quote]'
80 """
81 assert type(s) is str
82 for raw_value, escaped_value in ESCAPE_MAP.items():
83 s = s.replace(raw_value, escaped_value)
84 return s
85
86
87def unescape(s):

Callers 2

parse_string_contentFunction · 0.85

Calls 2

typeClass · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected