forked from 0xn0ne/weblogicScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.py
113 lines (84 loc) · 2.69 KB
/
state.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
DEFAULT_LANG = '_lang_cn'
class BaseState:
@classmethod
def to_dict(cls):
obj_dict = {}
for n in dir(cls):
v = getattr(cls, n)
if n.startswith('_') or callable(v):
continue
obj_dict[n] = v
return obj_dict
@classmethod
def text(cls, value: int, lang=DEFAULT_LANG):
if value not in cls.__dict__[lang]:
return 'error code'
return cls.__dict__[lang][value]
@classmethod
def group_to_dict(cls, value: int, lang=DEFAULT_LANG):
return {'code': value, 'msg': cls.text(value, lang)}
@classmethod
def group_to_list(cls, value: int, lang=DEFAULT_LANG):
return [value, cls.text(value, lang)]
class R(BaseState):
'''Response Content'''
SUCCESS = 0
FAILED = -255
TIMEOUT = -254
UNKNOWN = -253
TOO_FREQUENT = -252
DEPRECATED = -251
NOT_FOUND = -249
ALREADY_EXISTS = -248
PERMISSION_DENIED = -239
INVALID_ROLE = -238
CHECK_FAILURE = -229
PARAM_REQUIRED = -228
POSTDATA_REQUIRED = -227
INVALID_PARAMS = -219
INVALID_POSTDATA = -218
CONNET_FAILED = -209
WS_DONE = 1
_lang_cn = {
SUCCESS: '成功',
FAILED: '失败',
TIMEOUT: '超时',
UNKNOWN: '未知错误',
TOO_FREQUENT: '请求过于频繁',
DEPRECATED: '此接口已不推荐使用',
NOT_FOUND: '未找到',
ALREADY_EXISTS: '已存在',
PERMISSION_DENIED: '无权访问',
INVALID_ROLE: '权限申请失败',
CHECK_FAILURE: '校验失败',
PARAM_REQUIRED: '缺少参数',
POSTDATA_REQUIRED: '缺少提交内容',
INVALID_PARAMS: '非法参数',
INVALID_POSTDATA: '非法提交内容',
CONNET_FAILED: '连接失败',
WS_DONE: 'Websocket 请求完成'
}
_lang_en = {
SUCCESS: 'success',
FAILED: 'failed',
TIMEOUT: 'timeout',
UNKNOWN: 'unknown',
TOO_FREQUENT: 'request too frequent',
DEPRECATED: 'interface deprecated',
NOT_FOUND: 'not found',
ALREADY_EXISTS: 'already exists',
PERMISSION_DENIED: 'permission denied',
INVALID_ROLE: 'acquire role failed',
CHECK_FAILURE: 'check failure',
PARAM_REQUIRED: 'parameter(s) required',
POSTDATA_REQUIRED: 'post data item(s) required',
INVALID_PARAMS: 'invalid parameter(s)',
INVALID_POSTDATA: 'invalid post',
CONNET_FAILED: 'connection failed',
WS_DONE: 'Websocket request done'
}
if __name__ == '__main__':
print(R.to_dict())
print(R.text(R.FAILED))
print(R.group_to_dict(R.SUCCESS))
print(R.group_to_list(R.CONNET_FAILED))