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

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

18 statements  

1from __future__ import annotations 

2 

3# Importing the typing module would conflict with websockets.typing. 

4from typing import TYPE_CHECKING 

5 

6from .imports import lazy_import 

7from .version import version as __version__ # noqa: F401 

8 

9 

10__all__ = [ 

11 # .asyncio.client 

12 "connect", 

13 "unix_connect", 

14 "ClientConnection", 

15 # .asyncio.router 

16 "route", 

17 "unix_route", 

18 "Router", 

19 # .asyncio.server 

20 "basic_auth", 

21 "broadcast", 

22 "serve", 

23 "unix_serve", 

24 "ServerConnection", 

25 "Server", 

26 # .client 

27 "ClientProtocol", 

28 # .datastructures 

29 "Headers", 

30 "HeadersLike", 

31 "MultipleValuesError", 

32 # .exceptions 

33 "ConcurrencyError", 

34 "ConnectionClosed", 

35 "ConnectionClosedError", 

36 "ConnectionClosedOK", 

37 "DuplicateParameter", 

38 "HeaderLineTooLong", 

39 "InvalidHandshake", 

40 "InvalidHeader", 

41 "InvalidHeaderFormat", 

42 "InvalidHeaderValue", 

43 "InvalidMessage", 

44 "InvalidMethod", 

45 "InvalidOrigin", 

46 "InvalidParameterName", 

47 "InvalidParameterValue", 

48 "InvalidProtocol", 

49 "InvalidProxy", 

50 "InvalidProxyMessage", 

51 "InvalidProxyStatus", 

52 "InvalidState", 

53 "InvalidStatus", 

54 "InvalidUpgrade", 

55 "InvalidURI", 

56 "NegotiationError", 

57 "PayloadTooBig", 

58 "ProtocolError", 

59 "ProxyError", 

60 "RequestLineTooLong", 

61 "SecurityError", 

62 "StatusLineTooLong", 

63 "TooManyHeaders", 

64 "WebSocketException", 

65 # .frames 

66 "Close", 

67 "CloseCode", 

68 "Frame", 

69 "Opcode", 

70 # .http11 

71 "Request", 

72 "Response", 

73 # .protocol 

74 "Protocol", 

75 "Side", 

76 "State", 

77 # .server 

78 "ServerProtocol", 

79 # .typing 

80 "Data", 

81 "ExtensionName", 

82 "ExtensionParameter", 

83 "LoggerLike", 

84 "StatusLike", 

85 "Origin", 

86 "Subprotocol", 

87] 

88 

89# When type checking, import non-deprecated aliases eagerly. Else, import on demand. 

90if TYPE_CHECKING: 

91 from .asyncio.client import ClientConnection, connect, unix_connect 

92 from .asyncio.router import Router, route, unix_route 

93 from .asyncio.server import ( 

94 Server, 

95 ServerConnection, 

96 basic_auth, 

97 broadcast, 

98 serve, 

99 unix_serve, 

100 ) 

101 from .client import ClientProtocol 

102 from .datastructures import Headers, HeadersLike, MultipleValuesError 

103 from .exceptions import ( 

104 ConcurrencyError, 

105 ConnectionClosed, 

106 ConnectionClosedError, 

107 ConnectionClosedOK, 

108 DuplicateParameter, 

109 HeaderLineTooLong, 

110 InvalidHandshake, 

111 InvalidHeader, 

112 InvalidHeaderFormat, 

113 InvalidHeaderValue, 

114 InvalidMessage, 

115 InvalidMethod, 

116 InvalidOrigin, 

117 InvalidParameterName, 

118 InvalidParameterValue, 

119 InvalidProtocol, 

120 InvalidProxy, 

121 InvalidProxyMessage, 

122 InvalidProxyStatus, 

123 InvalidState, 

124 InvalidStatus, 

125 InvalidUpgrade, 

126 InvalidURI, 

127 NegotiationError, 

128 PayloadTooBig, 

129 ProtocolError, 

130 ProxyError, 

131 RequestLineTooLong, 

132 SecurityError, 

133 StatusLineTooLong, 

134 TooManyHeaders, 

135 WebSocketException, 

136 ) 

137 from .frames import Close, CloseCode, Frame, Opcode 

138 from .http11 import Request, Response 

139 from .protocol import Protocol, Side, State 

140 from .server import ServerProtocol 

141 from .typing import ( 

142 Data, 

143 ExtensionName, 

144 ExtensionParameter, 

145 LoggerLike, 

146 Origin, 

147 StatusLike, 

148 Subprotocol, 

149 ) 

150else: 

151 lazy_import( 

152 globals(), 

153 aliases={ 

154 # .asyncio.client 

155 "connect": ".asyncio.client", 

156 "unix_connect": ".asyncio.client", 

157 "ClientConnection": ".asyncio.client", 

158 # .asyncio.router 

159 "route": ".asyncio.router", 

160 "unix_route": ".asyncio.router", 

161 "Router": ".asyncio.router", 

162 # .asyncio.server 

163 "basic_auth": ".asyncio.server", 

164 "broadcast": ".asyncio.server", 

165 "serve": ".asyncio.server", 

166 "unix_serve": ".asyncio.server", 

167 "ServerConnection": ".asyncio.server", 

168 "Server": ".asyncio.server", 

169 # .client 

170 "ClientProtocol": ".client", 

171 # .datastructures 

172 "Headers": ".datastructures", 

173 "HeadersLike": ".datastructures", 

174 "MultipleValuesError": ".datastructures", 

175 # .exceptions 

176 "ConcurrencyError": ".exceptions", 

177 "ConnectionClosed": ".exceptions", 

178 "ConnectionClosedError": ".exceptions", 

179 "ConnectionClosedOK": ".exceptions", 

180 "DuplicateParameter": ".exceptions", 

181 "HeaderLineTooLong": ".exceptions", 

182 "InvalidHandshake": ".exceptions", 

183 "InvalidHeader": ".exceptions", 

184 "InvalidHeaderFormat": ".exceptions", 

185 "InvalidHeaderValue": ".exceptions", 

186 "InvalidMessage": ".exceptions", 

187 "InvalidMethod": ".exceptions", 

188 "InvalidOrigin": ".exceptions", 

189 "InvalidParameterName": ".exceptions", 

190 "InvalidParameterValue": ".exceptions", 

191 "InvalidProtocol": ".exceptions", 

192 "InvalidProxy": ".exceptions", 

193 "InvalidProxyMessage": ".exceptions", 

194 "InvalidProxyStatus": ".exceptions", 

195 "InvalidState": ".exceptions", 

196 "InvalidStatus": ".exceptions", 

197 "InvalidUpgrade": ".exceptions", 

198 "InvalidURI": ".exceptions", 

199 "NegotiationError": ".exceptions", 

200 "PayloadTooBig": ".exceptions", 

201 "ProtocolError": ".exceptions", 

202 "ProxyError": ".exceptions", 

203 "RequestLineTooLong": ".exceptions", 

204 "SecurityError": ".exceptions", 

205 "StatusLineTooLong": ".exceptions", 

206 "TooManyHeaders": ".exceptions", 

207 "WebSocketException": ".exceptions", 

208 # .frames 

209 "Close": ".frames", 

210 "CloseCode": ".frames", 

211 "Frame": ".frames", 

212 "Opcode": ".frames", 

213 # .http11 

214 "Request": ".http11", 

215 "Response": ".http11", 

216 # .protocol 

217 "Protocol": ".protocol", 

218 "Side": ".protocol", 

219 "State": ".protocol", 

220 # .server 

221 "ServerProtocol": ".server", 

222 # .typing 

223 "Data": ".typing", 

224 "ExtensionName": ".typing", 

225 "ExtensionParameter": ".typing", 

226 "LoggerLike": ".typing", 

227 "Origin": ".typing", 

228 "StatusLike": ".typing", 

229 "Subprotocol": ".typing", 

230 }, 

231 deprecated_aliases={ 

232 # deprecated in 14.0 - 2024-11-09 

233 # .legacy.auth 

234 "BasicAuthWebSocketServerProtocol": ".legacy.auth", 

235 "basic_auth_protocol_factory": ".legacy.auth", 

236 # .legacy.client 

237 "WebSocketClientProtocol": ".legacy.client", 

238 # .legacy.exceptions 

239 "AbortHandshake": ".legacy.exceptions", 

240 "InvalidStatusCode": ".legacy.exceptions", 

241 "RedirectHandshake": ".legacy.exceptions", 

242 "WebSocketProtocolError": ".legacy.exceptions", 

243 # .legacy.protocol 

244 "WebSocketCommonProtocol": ".legacy.protocol", 

245 # .legacy.server 

246 "WebSocketServer": ".legacy.server", 

247 "WebSocketServerProtocol": ".legacy.server", 

248 }, 

249 )