This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathconfig.py
88 lines (79 loc) · 2.43 KB
/
config.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
# -*- coding: utf-8 -*-
# @File : config.py
# @Date : 2019/8/28
# @Desc :
# @license : Copyright(C), funnywolf
# @Author: funnywolf
# @Contact : github.com/FunnyWolf
import base64
import logging
import logging.config
# 错误码
DATA = "DATA"
WRONG_DATA = b"WRONG DATA" # 错误格式的数据
INVALID_CONN = b"REMOVE CONN" # 无效的连接
# data = strings.Replace(strings.Replace(data, "\r\n", "", -1), "\n", "", -1)
def get_logger(level="INFO", name="StreamLogger"):
logconfig = {
'version': 1,
'formatters': {
'simple': {
'format': '%(asctime)s - %(levelname)s - %(lineno)s - %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'simple'
},
'file': {
'class': 'logging.FileHandler',
'filename': 'logging.log',
'level': 'DEBUG',
'formatter': 'simple'
},
},
'loggers': {
'StreamLogger': {
'handlers': ['console'],
'level': level,
},
'FileLogger': {
'handlers': ['file'],
'level': level,
},
}
}
logging.config.dictConfig(logconfig)
logger = logging.getLogger(name)
return logger
def b64decodeX(data):
if isinstance(data, str):
new_data = data.replace("\r\n", "")
new_data = new_data.replace("\n", "")
new_data = new_data.replace("-A", "+")
new_data = new_data.replace("-S", "/")
return base64.b64decode(new_data)
elif isinstance(data, bytes):
new_data = data.replace(b"\r\n", b"")
new_data = new_data.replace(b"\n", b"")
new_data = new_data.replace(b"-A", b"+")
new_data = new_data.replace(b"-S", b"/")
return base64.b64decode(new_data)
else:
print(data)
return base64.b64decode(data)
def b64encodeX(data):
new_data = base64.b64encode(data)
if isinstance(new_data, str):
new_data = new_data.replace("+", "-A")
new_data = new_data.replace("/", "-S")
return new_data
elif isinstance(new_data, bytes):
new_data = new_data.replace(b"+", b"-A")
new_data = new_data.replace(b"/", b"-S")
return new_data
else:
print(new_data)
return new_data