__init__.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. from __future__ import annotations
  2. # Importing the typing module would conflict with websockets.typing.
  3. from typing import TYPE_CHECKING
  4. from .imports import lazy_import
  5. from .version import version as __version__ # noqa: F401
  6. __all__ = [
  7. # .asyncio.client
  8. "connect",
  9. "unix_connect",
  10. "ClientConnection",
  11. # .asyncio.router
  12. "route",
  13. "unix_route",
  14. "Router",
  15. # .asyncio.server
  16. "basic_auth",
  17. "broadcast",
  18. "serve",
  19. "unix_serve",
  20. "ServerConnection",
  21. "Server",
  22. # .client
  23. "ClientProtocol",
  24. # .datastructures
  25. "Headers",
  26. "HeadersLike",
  27. "MultipleValuesError",
  28. # .exceptions
  29. "ConcurrencyError",
  30. "ConnectionClosed",
  31. "ConnectionClosedError",
  32. "ConnectionClosedOK",
  33. "DuplicateParameter",
  34. "InvalidHandshake",
  35. "InvalidHeader",
  36. "InvalidHeaderFormat",
  37. "InvalidHeaderValue",
  38. "InvalidMessage",
  39. "InvalidOrigin",
  40. "InvalidParameterName",
  41. "InvalidParameterValue",
  42. "InvalidProxy",
  43. "InvalidProxyMessage",
  44. "InvalidProxyStatus",
  45. "InvalidState",
  46. "InvalidStatus",
  47. "InvalidUpgrade",
  48. "InvalidURI",
  49. "NegotiationError",
  50. "PayloadTooBig",
  51. "ProtocolError",
  52. "ProxyError",
  53. "SecurityError",
  54. "WebSocketException",
  55. # .frames
  56. "Close",
  57. "CloseCode",
  58. "Frame",
  59. "Opcode",
  60. # .http11
  61. "Request",
  62. "Response",
  63. # .protocol
  64. "Protocol",
  65. "Side",
  66. "State",
  67. # .server
  68. "ServerProtocol",
  69. # .typing
  70. "Data",
  71. "ExtensionName",
  72. "ExtensionParameter",
  73. "LoggerLike",
  74. "StatusLike",
  75. "Origin",
  76. "Subprotocol",
  77. ]
  78. # When type checking, import non-deprecated aliases eagerly. Else, import on demand.
  79. if TYPE_CHECKING:
  80. from .asyncio.client import ClientConnection, connect, unix_connect
  81. from .asyncio.router import Router, route, unix_route
  82. from .asyncio.server import (
  83. Server,
  84. ServerConnection,
  85. basic_auth,
  86. broadcast,
  87. serve,
  88. unix_serve,
  89. )
  90. from .client import ClientProtocol
  91. from .datastructures import Headers, HeadersLike, MultipleValuesError
  92. from .exceptions import (
  93. ConcurrencyError,
  94. ConnectionClosed,
  95. ConnectionClosedError,
  96. ConnectionClosedOK,
  97. DuplicateParameter,
  98. InvalidHandshake,
  99. InvalidHeader,
  100. InvalidHeaderFormat,
  101. InvalidHeaderValue,
  102. InvalidMessage,
  103. InvalidOrigin,
  104. InvalidParameterName,
  105. InvalidParameterValue,
  106. InvalidProxy,
  107. InvalidProxyMessage,
  108. InvalidProxyStatus,
  109. InvalidState,
  110. InvalidStatus,
  111. InvalidUpgrade,
  112. InvalidURI,
  113. NegotiationError,
  114. PayloadTooBig,
  115. ProtocolError,
  116. ProxyError,
  117. SecurityError,
  118. WebSocketException,
  119. )
  120. from .frames import Close, CloseCode, Frame, Opcode
  121. from .http11 import Request, Response
  122. from .protocol import Protocol, Side, State
  123. from .server import ServerProtocol
  124. from .typing import (
  125. Data,
  126. ExtensionName,
  127. ExtensionParameter,
  128. LoggerLike,
  129. Origin,
  130. StatusLike,
  131. Subprotocol,
  132. )
  133. else:
  134. lazy_import(
  135. globals(),
  136. aliases={
  137. # .asyncio.client
  138. "connect": ".asyncio.client",
  139. "unix_connect": ".asyncio.client",
  140. "ClientConnection": ".asyncio.client",
  141. # .asyncio.router
  142. "route": ".asyncio.router",
  143. "unix_route": ".asyncio.router",
  144. "Router": ".asyncio.router",
  145. # .asyncio.server
  146. "basic_auth": ".asyncio.server",
  147. "broadcast": ".asyncio.server",
  148. "serve": ".asyncio.server",
  149. "unix_serve": ".asyncio.server",
  150. "ServerConnection": ".asyncio.server",
  151. "Server": ".asyncio.server",
  152. # .client
  153. "ClientProtocol": ".client",
  154. # .datastructures
  155. "Headers": ".datastructures",
  156. "HeadersLike": ".datastructures",
  157. "MultipleValuesError": ".datastructures",
  158. # .exceptions
  159. "ConcurrencyError": ".exceptions",
  160. "ConnectionClosed": ".exceptions",
  161. "ConnectionClosedError": ".exceptions",
  162. "ConnectionClosedOK": ".exceptions",
  163. "DuplicateParameter": ".exceptions",
  164. "InvalidHandshake": ".exceptions",
  165. "InvalidHeader": ".exceptions",
  166. "InvalidHeaderFormat": ".exceptions",
  167. "InvalidHeaderValue": ".exceptions",
  168. "InvalidMessage": ".exceptions",
  169. "InvalidOrigin": ".exceptions",
  170. "InvalidParameterName": ".exceptions",
  171. "InvalidParameterValue": ".exceptions",
  172. "InvalidProxy": ".exceptions",
  173. "InvalidProxyMessage": ".exceptions",
  174. "InvalidProxyStatus": ".exceptions",
  175. "InvalidState": ".exceptions",
  176. "InvalidStatus": ".exceptions",
  177. "InvalidUpgrade": ".exceptions",
  178. "InvalidURI": ".exceptions",
  179. "NegotiationError": ".exceptions",
  180. "PayloadTooBig": ".exceptions",
  181. "ProtocolError": ".exceptions",
  182. "ProxyError": ".exceptions",
  183. "SecurityError": ".exceptions",
  184. "WebSocketException": ".exceptions",
  185. # .frames
  186. "Close": ".frames",
  187. "CloseCode": ".frames",
  188. "Frame": ".frames",
  189. "Opcode": ".frames",
  190. # .http11
  191. "Request": ".http11",
  192. "Response": ".http11",
  193. # .protocol
  194. "Protocol": ".protocol",
  195. "Side": ".protocol",
  196. "State": ".protocol",
  197. # .server
  198. "ServerProtocol": ".server",
  199. # .typing
  200. "Data": ".typing",
  201. "ExtensionName": ".typing",
  202. "ExtensionParameter": ".typing",
  203. "LoggerLike": ".typing",
  204. "Origin": ".typing",
  205. "StatusLike": ".typing",
  206. "Subprotocol": ".typing",
  207. },
  208. deprecated_aliases={
  209. # deprecated in 9.0 - 2021-09-01
  210. "framing": ".legacy",
  211. "handshake": ".legacy",
  212. "parse_uri": ".uri",
  213. "WebSocketURI": ".uri",
  214. # deprecated in 14.0 - 2024-11-09
  215. # .legacy.auth
  216. "BasicAuthWebSocketServerProtocol": ".legacy.auth",
  217. "basic_auth_protocol_factory": ".legacy.auth",
  218. # .legacy.client
  219. "WebSocketClientProtocol": ".legacy.client",
  220. # .legacy.exceptions
  221. "AbortHandshake": ".legacy.exceptions",
  222. "InvalidStatusCode": ".legacy.exceptions",
  223. "RedirectHandshake": ".legacy.exceptions",
  224. "WebSocketProtocolError": ".legacy.exceptions",
  225. # .legacy.protocol
  226. "WebSocketCommonProtocol": ".legacy.protocol",
  227. # .legacy.server
  228. "WebSocketServer": ".legacy.server",
  229. "WebSocketServerProtocol": ".legacy.server",
  230. },
  231. )