MCPcopy Index your code
hub / github.com/python-websockets/websockets / parse_extension_item_param

Function parse_extension_item_param

src/websockets/headers.py:302–335  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

300
301
302def 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
338def parse_extension_item(

Callers 1

parse_extension_itemFunction · 0.85

Calls 5

parse_tokenFunction · 0.85
parse_OWSFunction · 0.85
peek_aheadFunction · 0.85
parse_quoted_stringFunction · 0.85
InvalidHeaderFormatClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…