Parse a quoted string from ``header`` at the given position. Return the unquoted value and the new position. Raises: InvalidHeaderFormat: On invalid inputs.
(header: str, pos: int, header_name: str)
| 128 | |
| 129 | |
| 130 | def parse_quoted_string(header: str, pos: int, header_name: str) -> tuple[str, int]: |
| 131 | """ |
| 132 | Parse a quoted string from ``header`` at the given position. |
| 133 | |
| 134 | Return the unquoted value and the new position. |
| 135 | |
| 136 | Raises: |
| 137 | InvalidHeaderFormat: On invalid inputs. |
| 138 | |
| 139 | """ |
| 140 | match = _quoted_string_re.match(header, pos) |
| 141 | if match is None: |
| 142 | raise InvalidHeaderFormat(header_name, "expected quoted string", header, pos) |
| 143 | return _unquote_re.sub(r"\1", match.group()[1:-1]), match.end() |
| 144 | |
| 145 | |
| 146 | _quotable_re = re.compile(r"[\x09\x20-\x7e\x80-\xff]*") |
no test coverage detected
searching dependent graphs…