-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.py
56 lines (41 loc) · 1.45 KB
/
error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import typing as t
if t.TYPE_CHECKING:
from message import SSHDisconnectReasonID
default_disconnect_messages = (
# 多加一个,这样 reason id 就跟数组的索引对上,不需要减一
"unknown error",
"SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT",
"SSH_DISCONNECT_PROTOCOL_ERROR",
"SSH_DISCONNECT_KEY_EXCHANGE_FAILED",
"SSH_DISCONNECT_RESERVED",
"SSH_DISCONNECT_MAC_ERROR",
"SSH_DISCONNECT_COMPRESSION_ERROR",
"SSH_DISCONNECT_SERVICE_NOT_AVAILABLE",
"SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED",
"SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE",
"SSH_DISCONNECT_CONNECTION_LOST",
"SSH_DISCONNECT_BY_APPLICATION",
"SSH_DISCONNECT_TOO_MANY_CONNECTIONS",
"SSH_DISCONNECT_AUTH_CANCELLED_BY_USER",
"SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE",
"SSH_DISCONNECT_ILLEGAL_USER_NAME",
)
class SSHError(Exception):
"""SSH 错误"""
class DisconnectError(SSHError):
"""断开连接"""
def __init__(
self, reason_id: "SSHDisconnectReasonID", description: t.Optional[str] = None
):
self.reason_id = reason_id
if description is None:
description = default_disconnect_messages[reason_id]
self.description = description
class UnsupportedError(SSHError):
"""未支持"""
class UnexpectedError(SSHError):
"""非预期行为"""
class BadRequestError(SSHError):
"""无效请求"""
class PacketTooLargeError(SSHError):
"""数据包太大"""