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

Function escapestr

Lib/test/test_strftime.py:19–29  ·  view source on GitHub ↗

Escape text to deal with possible locale values that have regex syntax while allowing regex syntax used for comparison.

(text, ampm)

Source from the content-addressed store, hash-verified

17 return s
18
19def escapestr(text, ampm):
20 """
21 Escape text to deal with possible locale values that have regex
22 syntax while allowing regex syntax used for comparison.
23 """
24 new_text = re.escape(text)
25 new_text = new_text.replace(re.escape(ampm), ampm)
26 new_text = new_text.replace(r'\%', '%')
27 new_text = new_text.replace(r'\:', ':')
28 new_text = new_text.replace(r'\?', '?')
29 return new_text
30
31
32class StrftimeTest(unittest.TestCase):

Callers 2

strftest1Method · 0.85
strftest2Method · 0.85

Calls 2

escapeMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…