INNER CODE UNIT · Python
safe_escape_curly_braces
mpenning/ciscoconfparse · ciscoconfparse/ccp_abc.py:431
def safe_escape_curly_braces(self, text):
"""
Escape curly braces in strings since they could be misunderstood as
f-string or string.format() delimiters...
If BaseCfgLine receives line with curly-braces, this method can
escape the curly braces so they are not mis-interpreted as python
string formatting delimiters.
"""
# Bypass escaping curly braces if there aren't any...
if not ("{" in text) and not ("}" in text):
return text
assert ("{" in text) or ("}" in text)
# Skip escaping curly braces if text already has double curly braces...
if ("{{" in text) or ("}}" in text):
return text