__init__.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. "HeaderLineTooLong",
  35. "InvalidHandshake",
  36. "InvalidHeader",
  37. "InvalidHeaderFormat",
  38. "InvalidHeaderValue",
  39. "InvalidMessage",
  40. "InvalidMethod",
  41. "InvalidOrigin",
  42. "InvalidParameterName",
  43. "InvalidParameterValue",
  44. "InvalidProtocol",
  45. "InvalidProxy",
  46. "InvalidProxyMessage",
  47. "InvalidProxyStatus",
  48. "InvalidState",
  49. "InvalidStatus",
  50. "InvalidUpgrade",
  51. "InvalidURI",
  52. "NegotiationError",
  53. "PayloadTooBig",
  54. "ProtocolError",
  55. "ProxyError",
  56. "RequestLineTooLong",
  57. "SecurityError",
  58. "StatusLineTooLong",
  59. "TooManyHeaders",
  60. "WebSocketException",
  61. # .frames
  62. "Close",
  63. "CloseCode",
  64. "Frame",
  65. "Opcode",
  66. # .http11
  67. "Request",
  68. "Response",
  69. # .protocol
  70. "Protocol",
  71. "Side",
  72. "State",
  73. # .server
  74. "ServerProtocol",
  75. # .typing
  76. "Data",
  77. "ExtensionName",
  78. "ExtensionParameter",
  79. "LoggerLike",
  80. "StatusLike",
  81. "Origin",
  82. "Subprotocol",
  83. ]
  84. # When type checking, import non-deprecated aliases eagerly. Else, import on demand.
  85. if TYPE_CHECKING:
  86. from .asyncio.client import ClientConnection, connect, unix_connect
  87. from .asyncio.router import Router, route, unix_route
  88. from .asyncio.server import (
  89. Server,
  90. ServerConnection,
  91. basic_auth,
  92. broadcast,
  93. serve,
  94. unix_serve,
  95. )
  96. from .client import ClientProtocol
  97. from .datastructures import Headers, HeadersLike, MultipleValuesError
  98. from .exceptions import (
  99. ConcurrencyError,
  100. ConnectionClosed,
  101. ConnectionClosedError,
  102. ConnectionClosedOK,
  103. DuplicateParameter,
  104. HeaderLineTooLong,
  105. InvalidHandshake,
  106. InvalidHeader,
  107. InvalidHeaderFormat,
  108. InvalidHeaderValue,
  109. InvalidMessage,
  110. InvalidMethod,
  111. InvalidOrigin,
  112. InvalidParameterName,
  113. InvalidParameterValue,
  114. InvalidProtocol,
  115. InvalidProxy,
  116. InvalidProxyMessage,
  117. InvalidProxyStatus,
  118. InvalidState,
  119. InvalidStatus,
  120. InvalidUpgrade,
  121. InvalidURI,
  122. NegotiationError,
  123. PayloadTooBig,
  124. ProtocolError,
  125. ProxyError,
  126. RequestLineTooLong,
  127. SecurityError,
  128. StatusLineTooLong,
  129. TooManyHeaders,
  130. WebSocketException,
  131. )
  132. from .frames import Close, CloseCode, Frame, Opcode
  133. from .http11 import Request, Response
  134. from .protocol import Protocol, Side, State
  135. from .server import ServerProtocol
  136. from .typing import (
  137. Data,
  138. ExtensionName,
  139. ExtensionParameter,
  140. LoggerLike,
  141. Origin,
  142. StatusLike,
  143. Subprotocol,
  144. )
  145. else:
  146. lazy_import(
  147. globals(),
  148. aliases={
  149. # .asyncio.client
  150. "connect": ".asyncio.client",
  151. "unix_connect": ".asyncio.client",
  152. "ClientConnection": ".asyncio.client",
  153. # .asyncio.router
  154. "route": ".asyncio.router",
  155. "unix_route": ".asyncio.router",
  156. "Router": ".asyncio.router",
  157. # .asyncio.server
  158. "basic_auth": ".asyncio.server",
  159. "broadcast": ".asyncio.server",
  160. "serve": ".asyncio.server",
  161. "unix_serve": ".asyncio.server",
  162. "ServerConnection": ".asyncio.server",
  163. "Server": ".asyncio.server",
  164. # .client
  165. "ClientProtocol": ".client",
  166. # .datastructures
  167. "Headers": ".datastructures",
  168. "HeadersLike": ".datastructures",
  169. "MultipleValuesError": ".datastructures",
  170. # .exceptions
  171. "ConcurrencyError": ".exceptions",
  172. "ConnectionClosed": ".exceptions",
  173. "ConnectionClosedError": ".exceptions",
  174. "ConnectionClosedOK": ".exceptions",
  175. "DuplicateParameter": ".exceptions",
  176. "HeaderLineTooLong": ".exceptions",
  177. "InvalidHandshake": ".exceptions",
  178. "InvalidHeader": ".exceptions",
  179. "InvalidHeaderFormat": ".exceptions",
  180. "InvalidHeaderValue": ".exceptions",
  181. "InvalidMessage": ".exceptions",
  182. "InvalidMethod": ".exceptions",
  183. "InvalidOrigin": ".exceptions",
  184. "InvalidParameterName": ".exceptions",
  185. "InvalidParameterValue": ".exceptions",
  186. "InvalidProtocol": ".exceptions",
  187. "InvalidProxy": ".exceptions",
  188. "InvalidProxyMessage": ".exceptions",
  189. "InvalidProxyStatus": ".exceptions",
  190. "InvalidState": ".exceptions",
  191. "InvalidStatus": ".exceptions",
  192. "InvalidUpgrade": ".exceptions",
  193. "InvalidURI": ".exceptions",
  194. "NegotiationError": ".exceptions",
  195. "PayloadTooBig": ".exceptions",
  196. "ProtocolError": ".exceptions",
  197. "ProxyError": ".exceptions",
  198. "RequestLineTooLong": ".exceptions",
  199. "SecurityError": ".exceptions",
  200. "StatusLineTooLong": ".exceptions",
  201. "TooManyHeaders": ".exceptions",
  202. "WebSocketException": ".exceptions",
  203. # .frames
  204. "Close": ".frames",
  205. "CloseCode": ".frames",
  206. "Frame": ".frames",
  207. "Opcode": ".frames",
  208. # .http11
  209. "Request": ".http11",
  210. "Response": ".http11",
  211. # .protocol
  212. "Protocol": ".protocol",
  213. "Side": ".protocol",
  214. "State": ".protocol",
  215. # .server
  216. "ServerProtocol": ".server",
  217. # .typing
  218. "Data": ".typing",
  219. "ExtensionName": ".typing",
  220. "ExtensionParameter": ".typing",
  221. "LoggerLike": ".typing",
  222. "Origin": ".typing",
  223. "StatusLike": ".typing",
  224. "Subprotocol": ".typing",
  225. },
  226. deprecated_aliases={
  227. # deprecated in 14.0 - 2024-11-09
  228. # .legacy.auth
  229. "BasicAuthWebSocketServerProtocol": ".legacy.auth",
  230. "basic_auth_protocol_factory": ".legacy.auth",
  231. # .legacy.client
  232. "WebSocketClientProtocol": ".legacy.client",
  233. # .legacy.exceptions
  234. "AbortHandshake": ".legacy.exceptions",
  235. "InvalidStatusCode": ".legacy.exceptions",
  236. "RedirectHandshake": ".legacy.exceptions",
  237. "WebSocketProtocolError": ".legacy.exceptions",
  238. # .legacy.protocol
  239. "WebSocketCommonProtocol": ".legacy.protocol",
  240. # .legacy.server
  241. "WebSocketServer": ".legacy.server",
  242. "WebSocketServerProtocol": ".legacy.server",
  243. },
  244. )