Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/websocket/_exceptions.py: 80%

20 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:34 +0000

1""" 

2_exceptions.py 

3websocket - WebSocket client library for Python 

4 

5Copyright 2023 engn33r 

6 

7Licensed under the Apache License, Version 2.0 (the "License"); 

8you may not use this file except in compliance with the License. 

9You may obtain a copy of the License at 

10 

11 http://www.apache.org/licenses/LICENSE-2.0 

12 

13Unless required by applicable law or agreed to in writing, software 

14distributed under the License is distributed on an "AS IS" BASIS, 

15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16See the License for the specific language governing permissions and 

17limitations under the License. 

18""" 

19 

20 

21class WebSocketException(Exception): 

22 """ 

23 WebSocket exception class. 

24 """ 

25 pass 

26 

27 

28class WebSocketProtocolException(WebSocketException): 

29 """ 

30 If the WebSocket protocol is invalid, this exception will be raised. 

31 """ 

32 pass 

33 

34 

35class WebSocketPayloadException(WebSocketException): 

36 """ 

37 If the WebSocket payload is invalid, this exception will be raised. 

38 """ 

39 pass 

40 

41 

42class WebSocketConnectionClosedException(WebSocketException): 

43 """ 

44 If remote host closed the connection or some network error happened, 

45 this exception will be raised. 

46 """ 

47 pass 

48 

49 

50class WebSocketTimeoutException(WebSocketException): 

51 """ 

52 WebSocketTimeoutException will be raised at socket timeout during read/write data. 

53 """ 

54 pass 

55 

56 

57class WebSocketProxyException(WebSocketException): 

58 """ 

59 WebSocketProxyException will be raised when proxy error occurred. 

60 """ 

61 pass 

62 

63 

64class WebSocketBadStatusException(WebSocketException): 

65 """ 

66 WebSocketBadStatusException will be raised when we get bad handshake status code. 

67 """ 

68 

69 def __init__(self, message: str, status_code: int, status_message=None, resp_headers=None, resp_body=None): 

70 super().__init__(message) 

71 self.status_code = status_code 

72 self.resp_headers = resp_headers 

73 self.resp_body = resp_body 

74 

75 

76class WebSocketAddressException(WebSocketException): 

77 """ 

78 If the websocket address info cannot be found, this exception will be raised. 

79 """ 

80 pass