MCPcopy
hub / github.com/django/django / unescape_string_literal

Function unescape_string_literal

django/utils/text.py:445–462  ·  view source on GitHub ↗

r""" Convert quoted string literals to unquoted strings with escaped quotes and backslashes unquoted:: >>> unescape_string_literal('"abc"') 'abc' >>> unescape_string_literal("'abc'") 'abc' >>> unescape_string_literal('"a \"bc\""') 'a "bc"'

(s)

Source from the content-addressed store, hash-verified

443
444@keep_lazy_text
445def unescape_string_literal(s):
446 r"""
447 Convert quoted string literals to unquoted strings with escaped quotes and
448 backslashes unquoted::
449
450 >>> unescape_string_literal('"abc"')
451 'abc'
452 >>> unescape_string_literal("'abc'")
453 'abc'
454 >>> unescape_string_literal('"a \"bc\""')
455 'a "bc"'
456 >>> unescape_string_literal("'\'ab\' c'")
457 "'ab' c"
458 """
459 if not s or s[0] not in "\"'" or s[-1] != s[0]:
460 raise ValueError("Not a string literal: %r" % s)
461 quote = s[0]
462 return s[1:-1].replace(r"\%s" % quote, quote).replace(r"\\", "\\")
463
464
465@keep_lazy_text

Callers 2

get_search_resultsMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected