Parse a single extension parameter from ``header`` at the given position. Return a ``(name, value)`` pair and the new position. Raises: InvalidHeaderFormat: On invalid inputs.
(
header: str, pos: int, header_name: str
)
| 300 | |
| 301 | |
| 302 | def parse_extension_item_param( |
| 303 | header: str, pos: int, header_name: str |
| 304 | ) -> tuple[ExtensionParameter, int]: |
| 305 | """ |
| 306 | Parse a single extension parameter from ``header`` at the given position. |
| 307 | |
| 308 | Return a ``(name, value)`` pair and the new position. |
| 309 | |
| 310 | Raises: |
| 311 | InvalidHeaderFormat: On invalid inputs. |
| 312 | |
| 313 | """ |
| 314 | # Extract parameter name. |
| 315 | name, pos = parse_token(header, pos, header_name) |
| 316 | pos = parse_OWS(header, pos) |
| 317 | # Extract parameter value, if there is one. |
| 318 | value: str | None = None |
| 319 | if peek_ahead(header, pos) == "=": |
| 320 | pos = parse_OWS(header, pos + 1) |
| 321 | if peek_ahead(header, pos) == '"': |
| 322 | pos_before = pos # for proper error reporting below |
| 323 | value, pos = parse_quoted_string(header, pos, header_name) |
| 324 | # https://datatracker.ietf.org/doc/html/rfc6455#section-9.1 says: |
| 325 | # the value after quoted-string unescaping MUST conform to |
| 326 | # the 'token' ABNF. |
| 327 | if _token_re.fullmatch(value) is None: |
| 328 | raise InvalidHeaderFormat( |
| 329 | header_name, "invalid quoted header content", header, pos_before |
| 330 | ) |
| 331 | else: |
| 332 | value, pos = parse_token(header, pos, header_name) |
| 333 | pos = parse_OWS(header, pos) |
| 334 | |
| 335 | return (name, value), pos |
| 336 | |
| 337 | |
| 338 | def parse_extension_item( |
no test coverage detected
searching dependent graphs…