Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/websockets/typing.py: 94%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3import http
4import logging
5from typing import TYPE_CHECKING, Any, NewType, Sequence
8__all__ = [
9 "Data",
10 "LoggerLike",
11 "StatusLike",
12 "Origin",
13 "Subprotocol",
14 "ExtensionName",
15 "ExtensionParameter",
16]
19# Public types used in the signature of public APIs
21Data = str | bytes
22"""Types supported in a WebSocket message:
23:class:`str` for a Text_ frame, :class:`bytes` for a Binary_ frame.
25.. _Text: https://datatracker.ietf.org/doc/html/rfc6455#section-5.6
26.. _Binary : https://datatracker.ietf.org/doc/html/rfc6455#section-5.6
28"""
30BytesLike = bytes | bytearray | memoryview
31"""Types accepted where :class:`bytes` is expected."""
33DataLike = str | bytes | bytearray | memoryview
34"""Types accepted where :class:`Data` is expected."""
36if TYPE_CHECKING:
37 LoggerLike = logging.Logger | logging.LoggerAdapter[Any]
38 """Types accepted where a :class:`~logging.Logger` is expected."""
39else: # remove this branch when dropping support for Python < 3.11
40 LoggerLike = logging.Logger | logging.LoggerAdapter
41 """Types accepted where a :class:`~logging.Logger` is expected."""
44StatusLike = http.HTTPStatus | int
45"""
46Types accepted where an :class:`~http.HTTPStatus` is expected."""
49Origin = NewType("Origin", str)
50"""Value of a ``Origin`` header."""
53Subprotocol = NewType("Subprotocol", str)
54"""Subprotocol in a ``Sec-WebSocket-Protocol`` header."""
57ExtensionName = NewType("ExtensionName", str)
58"""Name of a WebSocket extension."""
60ExtensionParameter = tuple[str, str | None]
61"""Parameter of a WebSocket extension."""
64# Private types
66ExtensionHeader = tuple[ExtensionName, Sequence[ExtensionParameter]]
67"""Extension in a ``Sec-WebSocket-Extensions`` header."""
70ConnectionOption = NewType("ConnectionOption", str)
71"""Connection option in a ``Connection`` header."""
74UpgradeProtocol = NewType("UpgradeProtocol", str)
75"""Upgrade protocol in an ``Upgrade`` header."""