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)
| 443 | |
| 444 | @keep_lazy_text |
| 445 | def 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 |
no outgoing calls
no test coverage detected