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

Function parse_basic_str_escape

Lib/tomllib/_parser.py:548–576  ·  view source on GitHub ↗
(
    src: str, pos: Pos, *, multiline: bool = False
)

Source from the content-addressed store, hash-verified

546
547
548def parse_basic_str_escape(
549 src: str, pos: Pos, *, multiline: bool = False
550) -> tuple[Pos, str]:
551 escape_id = src[pos : pos + 2]
552 pos += 2
553 if multiline and escape_id in {"\\ ", "\\\t", "\\\n"}:
554 # Skip whitespace until next non-whitespace character or end of
555 # the doc. Error if non-whitespace is found before newline.
556 if escape_id != "\\\n":
557 pos = skip_chars(src, pos, TOML_WS)
558 try:
559 char = src[pos]
560 except IndexError:
561 return pos, ""
562 if char != "\n":
563 raise TOMLDecodeError("Unescaped '\\' in a string", src, pos)
564 pos += 1
565 pos = skip_chars(src, pos, TOML_WS_AND_NEWLINE)
566 return pos, ""
567 if escape_id == "\\x":
568 return parse_hex_char(src, pos, 2)
569 if escape_id == "\\u":
570 return parse_hex_char(src, pos, 4)
571 if escape_id == "\\U":
572 return parse_hex_char(src, pos, 8)
573 try:
574 return pos, BASIC_STR_ESCAPE_REPLACEMENTS[escape_id]
575 except KeyError:
576 raise TOMLDecodeError("Unescaped '\\' in a string", src, pos) from None
577
578
579def parse_basic_str_escape_multiline(src: str, pos: Pos) -> tuple[Pos, str]:

Callers 1

Calls 3

skip_charsFunction · 0.85
TOMLDecodeErrorClass · 0.85
parse_hex_charFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…