Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/websockets/typing.py: 100%

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

29 statements  

1from __future__ import annotations 

2 

3import http 

4import logging 

5from typing import Any, NewType, Sequence 

6 

7 

8__all__ = [ 

9 "Data", 

10 "LoggerLike", 

11 "StatusLike", 

12 "Origin", 

13 "Subprotocol", 

14 "ExtensionName", 

15 "ExtensionParameter", 

16] 

17 

18 

19# Public types used in the signature of public APIs 

20 

21Data = str | bytes 

22"""Types supported in a WebSocket message: 

23:class:`str` for a Text_ frame, :class:`bytes` for a Binary_ frame. 

24 

25.. _Text: https://datatracker.ietf.org/doc/html/rfc6455#section-5.6 

26.. _Binary : https://datatracker.ietf.org/doc/html/rfc6455#section-5.6 

27 

28""" 

29 

30BytesLike = bytes | bytearray | memoryview 

31"""Types accepted where :class:`bytes` is expected.""" 

32 

33DataLike = str | bytes | bytearray | memoryview 

34"""Types accepted where :class:`Data` is expected.""" 

35 

36LoggerLike = logging.Logger | logging.LoggerAdapter[Any] 

37"""Types accepted where a :class:`~logging.Logger` is expected.""" 

38 

39 

40StatusLike = http.HTTPStatus | int 

41""" 

42Types accepted where an :class:`~http.HTTPStatus` is expected.""" 

43 

44 

45Origin = NewType("Origin", str) 

46"""Value of a ``Origin`` header.""" 

47 

48 

49Subprotocol = NewType("Subprotocol", str) 

50"""Subprotocol in a ``Sec-WebSocket-Protocol`` header.""" 

51 

52 

53ExtensionName = NewType("ExtensionName", str) 

54"""Name of a WebSocket extension.""" 

55 

56ExtensionParameter = tuple[str, str | None] 

57"""Parameter of a WebSocket extension.""" 

58 

59 

60# Private types 

61 

62ExtensionHeader = tuple[ExtensionName, Sequence[ExtensionParameter]] 

63"""Extension in a ``Sec-WebSocket-Extensions`` header.""" 

64 

65 

66ConnectionOption = NewType("ConnectionOption", str) 

67"""Connection option in a ``Connection`` header.""" 

68 

69 

70UpgradeProtocol = NewType("UpgradeProtocol", str) 

71"""Upgrade protocol in an ``Upgrade`` header."""