jit-utils-backend 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jit-utils-backend-0.0.1/MANIFEST.in +6 -0
- jit-utils-backend-0.0.1/PKG-INFO +178 -0
- jit-utils-backend-0.0.1/README.md +151 -0
- jit-utils-backend-0.0.1/jit_utils/__init__.py +152 -0
- jit-utils-backend-0.0.1/jit_utils/apiAuthSign.py +73 -0
- jit-utils-backend-0.0.1/jit_utils/barcode.py +50 -0
- jit-utils-backend-0.0.1/jit_utils/clsTool.py +71 -0
- jit-utils-backend-0.0.1/jit_utils/config/__init__.py +11 -0
- jit-utils-backend-0.0.1/jit_utils/config/case.py +77 -0
- jit-utils-backend-0.0.1/jit_utils/config/config.py +90 -0
- jit-utils-backend-0.0.1/jit_utils/config/exception.py +17 -0
- jit-utils-backend-0.0.1/jit_utils/config/field.py +177 -0
- jit-utils-backend-0.0.1/jit_utils/convert.py +169 -0
- jit-utils-backend-0.0.1/jit_utils/decorator.py +58 -0
- jit-utils-backend-0.0.1/jit_utils/exceptions.py +113 -0
- jit-utils-backend-0.0.1/jit_utils/forwarder.py +113 -0
- jit-utils-backend-0.0.1/jit_utils/matchTool.py +136 -0
- jit-utils-backend-0.0.1/jit_utils/network.py +36 -0
- jit-utils-backend-0.0.1/jit_utils/qrcode.py +60 -0
- jit-utils-backend-0.0.1/jit_utils/signature.py +56 -0
- jit-utils-backend-0.0.1/jit_utils/spaceSender.py +44 -0
- jit-utils-backend-0.0.1/jit_utils/string.py +118 -0
- jit-utils-backend-0.0.1/jit_utils/time.py +701 -0
- jit-utils-backend-0.0.1/jit_utils/validator.py +26 -0
- jit-utils-backend-0.0.1/jit_utils/workday_constants.py +72 -0
- jit-utils-backend-0.0.1/jit_utils_backend.egg-info/PKG-INFO +178 -0
- jit-utils-backend-0.0.1/jit_utils_backend.egg-info/SOURCES.txt +36 -0
- jit-utils-backend-0.0.1/jit_utils_backend.egg-info/dependency_links.txt +1 -0
- jit-utils-backend-0.0.1/jit_utils_backend.egg-info/requires.txt +4 -0
- jit-utils-backend-0.0.1/jit_utils_backend.egg-info/top_level.txt +2 -0
- jit-utils-backend-0.0.1/setup.cfg +4 -0
- jit-utils-backend-0.0.1/setup.py +67 -0
- jit-utils-backend-0.0.1/tests/__init__.py +4 -0
- jit-utils-backend-0.0.1/tests/run_tests.py +102 -0
- jit-utils-backend-0.0.1/tests/test_package_imports.py +199 -0
- jit-utils-backend-0.0.1/tests/test_qrcode_barcode.py +182 -0
- jit-utils-backend-0.0.1/tests/test_string_utils.py +174 -0
- jit-utils-backend-0.0.1/tests/test_time_utils.py +185 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: jit-utils-backend
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: 极态后端工具包
|
5
|
+
Author: zangtao
|
6
|
+
Author-email: noguchisyou123456@gmail.com
|
7
|
+
Project-URL: Documentation, https://github.com/zangtao/jit-utils-backend
|
8
|
+
Project-URL: Source, https://github.com/zangtao/jit-utils-backend
|
9
|
+
Project-URL: Tracker, https://github.com/zangtao/jit-utils-backend/issues
|
10
|
+
Keywords: python,jit,sdk,apiAuth,utils,backend
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
12
|
+
Classifier: Intended Audience :: Developers
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.6
|
15
|
+
Classifier: Programming Language :: Python :: 3.7
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
20
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
21
|
+
Classifier: Operating System :: Microsoft :: Windows
|
22
|
+
Classifier: Operating System :: POSIX :: Linux
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
24
|
+
Classifier: License :: OSI Approved :: MIT License
|
25
|
+
Requires-Python: >=3.6
|
26
|
+
Description-Content-Type: text/markdown
|
27
|
+
|
28
|
+
# JIT Utils Backend
|
29
|
+
|
30
|
+
极态后端工具包 - 一个为后端开发提供便利工具的 Python 包。
|
31
|
+
|
32
|
+
## 安装
|
33
|
+
|
34
|
+
```bash
|
35
|
+
pip install jit-utils-backend
|
36
|
+
```
|
37
|
+
|
38
|
+
## 使用方法
|
39
|
+
|
40
|
+
### 导入包
|
41
|
+
|
42
|
+
```python
|
43
|
+
# 导入整个包
|
44
|
+
import jit_utils
|
45
|
+
|
46
|
+
# 导入特定功能
|
47
|
+
from jit_utils import now, randomString, Qrcode, Barcode
|
48
|
+
|
49
|
+
# 导入特定模块
|
50
|
+
from jit_utils import time_utils, string_utils
|
51
|
+
```
|
52
|
+
|
53
|
+
## 主要功能
|
54
|
+
|
55
|
+
### 1. 时间处理工具
|
56
|
+
|
57
|
+
```python
|
58
|
+
from jit_utils import now, today, dayShift, formatNow
|
59
|
+
|
60
|
+
# 获取当前时间
|
61
|
+
current_time = now()
|
62
|
+
|
63
|
+
# 获取今天的日期
|
64
|
+
today_date = today()
|
65
|
+
|
66
|
+
# 日期偏移
|
67
|
+
tomorrow = dayShift(today_date, 1)
|
68
|
+
|
69
|
+
# 格式化当前时间
|
70
|
+
formatted_time = formatNow("%Y-%m-%d %H:%M:%S")
|
71
|
+
```
|
72
|
+
|
73
|
+
### 2. 字符串处理工具
|
74
|
+
|
75
|
+
```python
|
76
|
+
from jit_utils import randomString, md5Str, getUuidStr
|
77
|
+
|
78
|
+
# 生成随机字符串
|
79
|
+
random_str = randomString(8)
|
80
|
+
|
81
|
+
# MD5 加密
|
82
|
+
encrypted = md5Str("hello world")
|
83
|
+
|
84
|
+
# 生成 UUID
|
85
|
+
uuid_str = getUuidStr()
|
86
|
+
```
|
87
|
+
|
88
|
+
### 3. 二维码生成
|
89
|
+
|
90
|
+
```python
|
91
|
+
from jit_utils import Qrcode
|
92
|
+
|
93
|
+
# 创建二维码
|
94
|
+
qr = Qrcode("https://example.com")
|
95
|
+
|
96
|
+
# 获取二维码图片的字节数据
|
97
|
+
qr_bytes = qr.toByte()
|
98
|
+
|
99
|
+
# 获取二维码的 base64 字符串
|
100
|
+
qr_str = qr.toStr()
|
101
|
+
```
|
102
|
+
|
103
|
+
### 4. 条形码生成
|
104
|
+
|
105
|
+
```python
|
106
|
+
from jit_utils import Barcode
|
107
|
+
|
108
|
+
# 创建条形码
|
109
|
+
barcode = Barcode("123456789")
|
110
|
+
|
111
|
+
# 获取条形码图片的字节数据
|
112
|
+
barcode_bytes = barcode.toByte()
|
113
|
+
|
114
|
+
# 获取条形码的 base64 字符串
|
115
|
+
barcode_str = barcode.toStr()
|
116
|
+
```
|
117
|
+
|
118
|
+
### 5. 数据验证
|
119
|
+
|
120
|
+
```python
|
121
|
+
from jit_utils import ParamsValidator
|
122
|
+
from dataclasses import dataclass
|
123
|
+
|
124
|
+
@dataclass
|
125
|
+
class UserParams(ParamsValidator):
|
126
|
+
name: str
|
127
|
+
age: int
|
128
|
+
email: str = ""
|
129
|
+
|
130
|
+
# 验证参数
|
131
|
+
params = UserParams("test_function", name="John", age=25)
|
132
|
+
```
|
133
|
+
|
134
|
+
### 6. 装饰器
|
135
|
+
|
136
|
+
```python
|
137
|
+
from jit_utils import forward
|
138
|
+
|
139
|
+
@forward("module.submodule")
|
140
|
+
def my_function():
|
141
|
+
pass
|
142
|
+
```
|
143
|
+
|
144
|
+
## 模块说明
|
145
|
+
|
146
|
+
- **time_utils**: 时间处理相关工具
|
147
|
+
- **string_utils**: 字符串处理相关工具
|
148
|
+
- **qrcode**: 二维码生成工具
|
149
|
+
- **barcode**: 条形码生成工具
|
150
|
+
- **validator**: 数据验证工具
|
151
|
+
- **network**: 网络相关工具
|
152
|
+
- **signature**: 签名相关工具
|
153
|
+
- **matchTool**: 匹配工具
|
154
|
+
- **clsTool**: 类工具
|
155
|
+
- **exceptions**: 异常处理
|
156
|
+
- **workday_constants**: 工作日常量
|
157
|
+
- **config**: 配置相关工具
|
158
|
+
|
159
|
+
## 依赖包
|
160
|
+
|
161
|
+
- requests
|
162
|
+
- qrcode
|
163
|
+
- python-barcode
|
164
|
+
- Pillow
|
165
|
+
- arrow
|
166
|
+
- python-dateutil
|
167
|
+
|
168
|
+
## 许可证
|
169
|
+
|
170
|
+
MIT License
|
171
|
+
|
172
|
+
## 作者
|
173
|
+
|
174
|
+
zangtao (noguchisyou123456@gmail.com)
|
175
|
+
|
176
|
+
## 版本
|
177
|
+
|
178
|
+
0.0.1
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# JIT Utils Backend
|
2
|
+
|
3
|
+
极态后端工具包 - 一个为后端开发提供便利工具的 Python 包。
|
4
|
+
|
5
|
+
## 安装
|
6
|
+
|
7
|
+
```bash
|
8
|
+
pip install jit-utils-backend
|
9
|
+
```
|
10
|
+
|
11
|
+
## 使用方法
|
12
|
+
|
13
|
+
### 导入包
|
14
|
+
|
15
|
+
```python
|
16
|
+
# 导入整个包
|
17
|
+
import jit_utils
|
18
|
+
|
19
|
+
# 导入特定功能
|
20
|
+
from jit_utils import now, randomString, Qrcode, Barcode
|
21
|
+
|
22
|
+
# 导入特定模块
|
23
|
+
from jit_utils import time_utils, string_utils
|
24
|
+
```
|
25
|
+
|
26
|
+
## 主要功能
|
27
|
+
|
28
|
+
### 1. 时间处理工具
|
29
|
+
|
30
|
+
```python
|
31
|
+
from jit_utils import now, today, dayShift, formatNow
|
32
|
+
|
33
|
+
# 获取当前时间
|
34
|
+
current_time = now()
|
35
|
+
|
36
|
+
# 获取今天的日期
|
37
|
+
today_date = today()
|
38
|
+
|
39
|
+
# 日期偏移
|
40
|
+
tomorrow = dayShift(today_date, 1)
|
41
|
+
|
42
|
+
# 格式化当前时间
|
43
|
+
formatted_time = formatNow("%Y-%m-%d %H:%M:%S")
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. 字符串处理工具
|
47
|
+
|
48
|
+
```python
|
49
|
+
from jit_utils import randomString, md5Str, getUuidStr
|
50
|
+
|
51
|
+
# 生成随机字符串
|
52
|
+
random_str = randomString(8)
|
53
|
+
|
54
|
+
# MD5 加密
|
55
|
+
encrypted = md5Str("hello world")
|
56
|
+
|
57
|
+
# 生成 UUID
|
58
|
+
uuid_str = getUuidStr()
|
59
|
+
```
|
60
|
+
|
61
|
+
### 3. 二维码生成
|
62
|
+
|
63
|
+
```python
|
64
|
+
from jit_utils import Qrcode
|
65
|
+
|
66
|
+
# 创建二维码
|
67
|
+
qr = Qrcode("https://example.com")
|
68
|
+
|
69
|
+
# 获取二维码图片的字节数据
|
70
|
+
qr_bytes = qr.toByte()
|
71
|
+
|
72
|
+
# 获取二维码的 base64 字符串
|
73
|
+
qr_str = qr.toStr()
|
74
|
+
```
|
75
|
+
|
76
|
+
### 4. 条形码生成
|
77
|
+
|
78
|
+
```python
|
79
|
+
from jit_utils import Barcode
|
80
|
+
|
81
|
+
# 创建条形码
|
82
|
+
barcode = Barcode("123456789")
|
83
|
+
|
84
|
+
# 获取条形码图片的字节数据
|
85
|
+
barcode_bytes = barcode.toByte()
|
86
|
+
|
87
|
+
# 获取条形码的 base64 字符串
|
88
|
+
barcode_str = barcode.toStr()
|
89
|
+
```
|
90
|
+
|
91
|
+
### 5. 数据验证
|
92
|
+
|
93
|
+
```python
|
94
|
+
from jit_utils import ParamsValidator
|
95
|
+
from dataclasses import dataclass
|
96
|
+
|
97
|
+
@dataclass
|
98
|
+
class UserParams(ParamsValidator):
|
99
|
+
name: str
|
100
|
+
age: int
|
101
|
+
email: str = ""
|
102
|
+
|
103
|
+
# 验证参数
|
104
|
+
params = UserParams("test_function", name="John", age=25)
|
105
|
+
```
|
106
|
+
|
107
|
+
### 6. 装饰器
|
108
|
+
|
109
|
+
```python
|
110
|
+
from jit_utils import forward
|
111
|
+
|
112
|
+
@forward("module.submodule")
|
113
|
+
def my_function():
|
114
|
+
pass
|
115
|
+
```
|
116
|
+
|
117
|
+
## 模块说明
|
118
|
+
|
119
|
+
- **time_utils**: 时间处理相关工具
|
120
|
+
- **string_utils**: 字符串处理相关工具
|
121
|
+
- **qrcode**: 二维码生成工具
|
122
|
+
- **barcode**: 条形码生成工具
|
123
|
+
- **validator**: 数据验证工具
|
124
|
+
- **network**: 网络相关工具
|
125
|
+
- **signature**: 签名相关工具
|
126
|
+
- **matchTool**: 匹配工具
|
127
|
+
- **clsTool**: 类工具
|
128
|
+
- **exceptions**: 异常处理
|
129
|
+
- **workday_constants**: 工作日常量
|
130
|
+
- **config**: 配置相关工具
|
131
|
+
|
132
|
+
## 依赖包
|
133
|
+
|
134
|
+
- requests
|
135
|
+
- qrcode
|
136
|
+
- python-barcode
|
137
|
+
- Pillow
|
138
|
+
- arrow
|
139
|
+
- python-dateutil
|
140
|
+
|
141
|
+
## 许可证
|
142
|
+
|
143
|
+
MIT License
|
144
|
+
|
145
|
+
## 作者
|
146
|
+
|
147
|
+
zangtao (noguchisyou123456@gmail.com)
|
148
|
+
|
149
|
+
## 版本
|
150
|
+
|
151
|
+
0.0.1
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# -*-coding:utf-8-*-
|
2
|
+
"""
|
3
|
+
JIT Utils Backend - 极态后端工具包
|
4
|
+
|
5
|
+
A comprehensive utility package for backend development with JIT.
|
6
|
+
|
7
|
+
主要功能:
|
8
|
+
- 时间处理工具
|
9
|
+
- 字符串处理工具
|
10
|
+
- 二维码和条形码生成
|
11
|
+
- 数据验证
|
12
|
+
- 网络工具
|
13
|
+
- 签名工具
|
14
|
+
等等...
|
15
|
+
"""
|
16
|
+
|
17
|
+
__version__ = '0.0.1'
|
18
|
+
__author__ = 'zangtao'
|
19
|
+
|
20
|
+
# 导入主要的工具类和函数
|
21
|
+
try:
|
22
|
+
from .decorator import forward
|
23
|
+
except ImportError:
|
24
|
+
pass
|
25
|
+
|
26
|
+
# 时间工具
|
27
|
+
try:
|
28
|
+
from . import time as time_utils
|
29
|
+
# 导出一些常用的时间函数
|
30
|
+
from .time import (
|
31
|
+
now, today, get, dayShift,
|
32
|
+
monday, weekShift, monthStart, monthShift,
|
33
|
+
quarterStart, quarterShift, yearStart, yearShift,
|
34
|
+
getTimestamp, timeStampToDateTime, strToTimestamp,
|
35
|
+
formatNow, datetime2string, string2datetime
|
36
|
+
)
|
37
|
+
except ImportError:
|
38
|
+
pass
|
39
|
+
|
40
|
+
# 字符串工具
|
41
|
+
try:
|
42
|
+
from . import string as string_utils
|
43
|
+
from .string import (
|
44
|
+
randomString, randomNum, getUuidStr,
|
45
|
+
md5Bytes, md5Str, getFileMd5,
|
46
|
+
renderTemplateString
|
47
|
+
)
|
48
|
+
except ImportError:
|
49
|
+
pass
|
50
|
+
|
51
|
+
# 二维码工具
|
52
|
+
try:
|
53
|
+
from .qrcode import Qrcode
|
54
|
+
except ImportError:
|
55
|
+
Qrcode = None
|
56
|
+
|
57
|
+
# 条形码工具
|
58
|
+
try:
|
59
|
+
from .barcode import Barcode
|
60
|
+
except ImportError:
|
61
|
+
Barcode = None
|
62
|
+
|
63
|
+
# 验证工具
|
64
|
+
try:
|
65
|
+
from .validator import ParamsValidator
|
66
|
+
except ImportError:
|
67
|
+
ParamsValidator = None
|
68
|
+
|
69
|
+
# 网络工具
|
70
|
+
try:
|
71
|
+
from . import network
|
72
|
+
except ImportError:
|
73
|
+
pass
|
74
|
+
|
75
|
+
# 签名工具
|
76
|
+
try:
|
77
|
+
from . import signature
|
78
|
+
except ImportError:
|
79
|
+
pass
|
80
|
+
|
81
|
+
# 匹配工具
|
82
|
+
try:
|
83
|
+
from . import matchTool
|
84
|
+
except ImportError:
|
85
|
+
pass
|
86
|
+
|
87
|
+
# 类工具
|
88
|
+
try:
|
89
|
+
from . import clsTool
|
90
|
+
except ImportError:
|
91
|
+
pass
|
92
|
+
|
93
|
+
# 转换工具
|
94
|
+
try:
|
95
|
+
from .convert import Converter, MemoryCompiler
|
96
|
+
except ImportError:
|
97
|
+
# 如果导入失败,创建占位符避免 __all__ 报错
|
98
|
+
Converter = None
|
99
|
+
MemoryCompiler = None
|
100
|
+
|
101
|
+
# 异常处理
|
102
|
+
try:
|
103
|
+
from . import exceptions
|
104
|
+
except ImportError:
|
105
|
+
pass
|
106
|
+
|
107
|
+
# 工作日常量
|
108
|
+
try:
|
109
|
+
from . import workday_constants
|
110
|
+
except ImportError:
|
111
|
+
pass
|
112
|
+
|
113
|
+
# 配置相关
|
114
|
+
try:
|
115
|
+
from . import config
|
116
|
+
except ImportError:
|
117
|
+
pass
|
118
|
+
|
119
|
+
# 定义 __all__ 列表,控制 from jit_utils import * 的行为
|
120
|
+
__all__ = [
|
121
|
+
# 版本信息
|
122
|
+
'__version__',
|
123
|
+
'__author__',
|
124
|
+
|
125
|
+
# 装饰器
|
126
|
+
'forward',
|
127
|
+
|
128
|
+
# 时间工具
|
129
|
+
'time_utils',
|
130
|
+
'now', 'today', 'get', 'dayShift',
|
131
|
+
'monday', 'weekShift', 'monthStart', 'monthShift',
|
132
|
+
'quarterStart', 'quarterShift', 'yearStart', 'yearShift',
|
133
|
+
'getTimestamp', 'timeStampToDateTime', 'strToTimestamp',
|
134
|
+
'formatNow', 'datetime2string', 'string2datetime',
|
135
|
+
|
136
|
+
# 字符串工具
|
137
|
+
'string_utils',
|
138
|
+
'randomString', 'randomNum', 'getUuidStr',
|
139
|
+
'md5Bytes', 'md5Str', 'getFileMd5',
|
140
|
+
'renderTemplateString',
|
141
|
+
|
142
|
+
# 二维码和条形码
|
143
|
+
'Qrcode', 'Barcode',
|
144
|
+
|
145
|
+
# 验证工具
|
146
|
+
'ParamsValidator',
|
147
|
+
|
148
|
+
# 其他模块
|
149
|
+
'network', 'signature', 'matchTool',
|
150
|
+
'clsTool', 'exceptions', 'workday_constants',
|
151
|
+
'config', 'Converter', 'MemoryCompiler'
|
152
|
+
]
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*-coding:utf-8-*-
|
2
|
+
"""
|
3
|
+
Created on 2024/11/09
|
4
|
+
|
5
|
+
@author: 臧韬
|
6
|
+
|
7
|
+
@desc: 默认描述
|
8
|
+
"""
|
9
|
+
|
10
|
+
import base64
|
11
|
+
import hashlib
|
12
|
+
import json
|
13
|
+
import time
|
14
|
+
|
15
|
+
from jit.commons.utils.logger import log
|
16
|
+
|
17
|
+
|
18
|
+
class Sign(object):
|
19
|
+
"""
|
20
|
+
这个签名算法用于认证服务和api授权元素
|
21
|
+
"""
|
22
|
+
|
23
|
+
EXPIRE_TIME = 5 * 60 * 1000
|
24
|
+
# 签名返回的错误信息,如果是错误信息,返回空tuple,兼容原来通过bool方法校验签名是否通过的写法
|
25
|
+
TIME_OUT_ERROR = []
|
26
|
+
SIGN_CHECK_ERROR = []
|
27
|
+
SIGN_CHECK_SUCCESS = [0]
|
28
|
+
|
29
|
+
def __init__(self, secret):
|
30
|
+
self.secret = secret
|
31
|
+
|
32
|
+
def encode(self, args, timestamp, debug=False):
|
33
|
+
return self.getSign({**args, "timestamp": timestamp, "secret": self.secret}, debug=debug)
|
34
|
+
|
35
|
+
@staticmethod
|
36
|
+
def getSign(args, debug=False):
|
37
|
+
nArgs = {}
|
38
|
+
for k, v in args.items():
|
39
|
+
nArgs[k.lower()] = v
|
40
|
+
sortedKeys = sorted(nArgs.keys())
|
41
|
+
params = []
|
42
|
+
for key in sortedKeys:
|
43
|
+
value = nArgs[key]
|
44
|
+
if not isinstance(value, str):
|
45
|
+
value = json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
46
|
+
params.append(f"{key}={value}")
|
47
|
+
if debug:
|
48
|
+
# 隐藏secret
|
49
|
+
for idx, param in enumerate(params):
|
50
|
+
if param.split("=")[0] == "secret":
|
51
|
+
params[idx] = "secret=*********************"
|
52
|
+
|
53
|
+
paramStr = "&".join(params)
|
54
|
+
|
55
|
+
apiAuthDebug = {
|
56
|
+
"paramStr": paramStr,
|
57
|
+
}
|
58
|
+
log.debug(",".join("{k}:{v}".format(k=k, v=v) for k, v in apiAuthDebug.items()))
|
59
|
+
if hasattr(app.request, "respExtraData"):
|
60
|
+
app.request.respExtraData["apiAuthDebug"] = apiAuthDebug
|
61
|
+
return hashlib.sha1(base64.b64encode("&".join(params).encode("utf-8"))).hexdigest()
|
62
|
+
|
63
|
+
def verify(self, args):
|
64
|
+
args = args.copy()
|
65
|
+
timestamp = args.pop("timestamp")
|
66
|
+
if abs(int(time.time() * 1000) - int(timestamp)) > self.EXPIRE_TIME:
|
67
|
+
return self.TIME_OUT_ERROR
|
68
|
+
signature = args.pop("accessSign")
|
69
|
+
debug = app.request.headers.get("debug") == "1"
|
70
|
+
if signature == self.encode(args, timestamp, debug=debug):
|
71
|
+
return self.SIGN_CHECK_SUCCESS
|
72
|
+
else:
|
73
|
+
return self.SIGN_CHECK_ERROR
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*-coding:utf-8-*-
|
2
|
+
"""
|
3
|
+
Created on 2025/02/10
|
4
|
+
|
5
|
+
@author: 臧韬
|
6
|
+
|
7
|
+
@desc: 默认描述
|
8
|
+
"""
|
9
|
+
import base64
|
10
|
+
import io
|
11
|
+
|
12
|
+
import barcode
|
13
|
+
from barcode.errors import BarcodeError
|
14
|
+
from barcode.writer import ImageWriter
|
15
|
+
|
16
|
+
|
17
|
+
class Barcode(object):
|
18
|
+
"""
|
19
|
+
二维码模块,暂用于文件渲染
|
20
|
+
"""
|
21
|
+
|
22
|
+
def __init__(self, value: str, codeType="code128"):
|
23
|
+
self.value = value
|
24
|
+
self.codeType = codeType
|
25
|
+
|
26
|
+
def toByte(self):
|
27
|
+
file = self.toFile()
|
28
|
+
data = file.read()
|
29
|
+
return data
|
30
|
+
|
31
|
+
def toFile(self):
|
32
|
+
obj = barcode.get(self.codeType, self.value, writer=ImageWriter())
|
33
|
+
# 保存条形码为图像文件
|
34
|
+
imageBuffer = io.BytesIO()
|
35
|
+
obj.write(fp=imageBuffer)
|
36
|
+
imageBuffer.seek(0)
|
37
|
+
return imageBuffer
|
38
|
+
|
39
|
+
def toStr(self):
|
40
|
+
if not self.value:
|
41
|
+
return ""
|
42
|
+
try:
|
43
|
+
b64Code = base64.b64encode(self.toByte()).decode("utf-8")
|
44
|
+
except BarcodeError as e:
|
45
|
+
return "ERROR:{}".format(str(e))
|
46
|
+
|
47
|
+
return "<image:{}>".format(b64Code)
|
48
|
+
|
49
|
+
def __str__(self):
|
50
|
+
return self.toStr()
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# -*-coding:utf-8-*-
|
2
|
+
"""
|
3
|
+
Created on 2024/09/29
|
4
|
+
|
5
|
+
@author: 臧韬
|
6
|
+
|
7
|
+
@desc: 因为框架打包不重启的时候会出现isinstance方法和issubclass函数出现问题,
|
8
|
+
所以重新实现这两个方法,通过类名来确定是否为子类,而不是通过对象ID。
|
9
|
+
"""
|
10
|
+
|
11
|
+
|
12
|
+
def issubclassByName(cls, class_or_tuple: type | tuple):
|
13
|
+
if isinstance(class_or_tuple, tuple):
|
14
|
+
for cls_name in class_or_tuple:
|
15
|
+
if issubclassByName(cls, cls_name):
|
16
|
+
return True
|
17
|
+
else:
|
18
|
+
return False
|
19
|
+
|
20
|
+
if not isinstance(cls, type):
|
21
|
+
raise TypeError("issubclassByName() arg 0 must be a class")
|
22
|
+
|
23
|
+
if not isinstance(class_or_tuple, type):
|
24
|
+
raise TypeError("isinstanceByName() arg 1 must be a class or tuple with class")
|
25
|
+
|
26
|
+
__className = class_or_tuple.__name__
|
27
|
+
if cls is type:
|
28
|
+
# 特殊情况
|
29
|
+
mroNames = [item.__name__ for item in type.mro(type)]
|
30
|
+
else:
|
31
|
+
mroNames = [item.__name__ for item in cls.mro()]
|
32
|
+
if __className in mroNames:
|
33
|
+
return True
|
34
|
+
else:
|
35
|
+
return False
|
36
|
+
|
37
|
+
|
38
|
+
def isinstanceByName(obj, class_or_tuple: type | tuple):
|
39
|
+
if isinstance(class_or_tuple, tuple):
|
40
|
+
for cls_name in class_or_tuple:
|
41
|
+
if isinstanceByName(obj, cls_name):
|
42
|
+
return True
|
43
|
+
else:
|
44
|
+
return False
|
45
|
+
|
46
|
+
if not isinstance(obj, object):
|
47
|
+
raise TypeError("isinstanceByName() arg 0 must be an object")
|
48
|
+
|
49
|
+
if not isinstance(class_or_tuple, type):
|
50
|
+
raise TypeError("isinstanceByName() arg 1 must be a class or tuple with class")
|
51
|
+
|
52
|
+
cls = type(obj)
|
53
|
+
if cls.__name__ == class_or_tuple.__name__:
|
54
|
+
return True
|
55
|
+
return issubclassByName(cls, class_or_tuple)
|
56
|
+
|
57
|
+
|
58
|
+
if __name__ == "__main__":
|
59
|
+
A = type("A", (object,), {})
|
60
|
+
B = type("B", (A,), {})
|
61
|
+
|
62
|
+
a = A()
|
63
|
+
b = B()
|
64
|
+
|
65
|
+
print("class B is subclass of A: ", issubclassByName(B, A))
|
66
|
+
print("object b is instance of A: ", isinstanceByName(b, A))
|
67
|
+
print("object b is instance of B: ", isinstanceByName(b, B))
|
68
|
+
print("object b is instance of B or A: ", isinstanceByName(b, (B, A)))
|
69
|
+
print("object a is instance of object: ", isinstanceByName(a, object))
|
70
|
+
print("class A is instance of type: ", isinstanceByName(A, type))
|
71
|
+
print("object a is not instance of type: ", not isinstanceByName(a, type))
|