tretool 0.2.1__py3-none-any.whl → 1.0.0__py3-none-any.whl
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.
- tretool/__init__.py +39 -12
- tretool/config.py +406 -170
- tretool/decoratorlib.py +423 -0
- tretool/encoding.py +404 -75
- tretool/httplib.py +730 -0
- tretool/jsonlib.py +619 -151
- tretool/logger.py +712 -0
- tretool/mathlib.py +0 -33
- tretool/path.py +19 -0
- tretool/platformlib.py +469 -314
- tretool/plugin.py +437 -237
- tretool/smartCache.py +569 -0
- tretool/tasklib.py +730 -0
- tretool/transform/docx.py +544 -0
- tretool/transform/pdf.py +273 -95
- tretool/ziplib.py +664 -0
- {tretool-0.2.1.dist-info → tretool-1.0.0.dist-info}/METADATA +11 -5
- tretool-1.0.0.dist-info/RECORD +24 -0
- tretool/markfunc.py +0 -152
- tretool/memorizeTools.py +0 -24
- tretool/writeLog.py +0 -69
- tretool-0.2.1.dist-info/RECORD +0 -20
- {tretool-0.2.1.dist-info → tretool-1.0.0.dist-info}/WHEEL +0 -0
- {tretool-0.2.1.dist-info → tretool-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {tretool-0.2.1.dist-info → tretool-1.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
tretool/__init__.py,sha256=l0ufgWz4BFP1WSrnDh80T7GCFOIudoJgXBuwwZYBz54,1434
|
2
|
+
tretool/config.py,sha256=Lmu3w5RRjGkX3T36EWdLonztvcKQq0mRvjZ2XU0R01A,16601
|
3
|
+
tretool/decoratorlib.py,sha256=Vz3275svoHd28yPZyJFF-uF_oVoKuHPsU-_skMohF0Q,15460
|
4
|
+
tretool/encoding.py,sha256=pysRjF-RDw1iVlM6J8yME6EEZTHcB9SnWofNk_B1cog,15341
|
5
|
+
tretool/httplib.py,sha256=VpXv9QG69UIE1hIbCxjnMBKH2Jo5DGIF8l9cdDcjaNQ,28095
|
6
|
+
tretool/jsonlib.py,sha256=FehNGARwy7CHWxaopQpwj1eB8g0SU4-MEIJxehFb7Tk,25060
|
7
|
+
tretool/logger.py,sha256=1WynCnxqE5s6QhrS3vPxIST7ojifF0SexOJxp-4NbbU,22971
|
8
|
+
tretool/mathlib.py,sha256=EptmGm0lymi0gzAzCBgVHPBa26GEhqTEsHbYBc8qvlA,18582
|
9
|
+
tretool/path.py,sha256=rj3DYlBNhORGJhdPb4yFIS8nryfOqWZ6H7SHwkPt67o,32525
|
10
|
+
tretool/platformlib.py,sha256=EdpGnJg8n08q9xf8_SrsooFKV6Lt4VURTDu3cpmu7x4,16635
|
11
|
+
tretool/plugin.py,sha256=CacUi_1iapnBVejfmf5vj5oE26-NIAPajVZ2I3QIQt4,20048
|
12
|
+
tretool/smartCache.py,sha256=OuH98BsrWC_F-bqhCRomBvFcuVWvfVnc_iyQfZpo_40,18513
|
13
|
+
tretool/tasklib.py,sha256=rEME3kt5K2yXAr9gYdl5keBA15Wchm2POluFHBhUwUM,25867
|
14
|
+
tretool/timelib.py,sha256=XH1o8WDoj4W41vO-AuRV782d6IuqvmcCuKEkdabHsjg,16559
|
15
|
+
tretool/ziplib.py,sha256=tRlaOQDEGETBjl6M4tnQ7Wz-GzQL2bfryLj1rKHa_9s,24742
|
16
|
+
tretool/plugin/plu.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
tretool/transform/__init__.py,sha256=-0UKgEwky5AAV_UNGSRdKhYbrkAjUHZIO4Lj0z-ITPE,17
|
18
|
+
tretool/transform/docx.py,sha256=zWYJxYuHvy4YUcUkuoJHx78qqnWwR7spP1KDltKYFek,19863
|
19
|
+
tretool/transform/pdf.py,sha256=rYgXbZDSCx_405KK_FP2ZfiBKVr-EI8wwi_S9-ImHNk,20990
|
20
|
+
tretool-1.0.0.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
21
|
+
tretool-1.0.0.dist-info/METADATA,sha256=QgRN5n9vyfakFhBtIkWQZ5VfX-LCxGlDKf6vr7Cfnl4,953
|
22
|
+
tretool-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
tretool-1.0.0.dist-info/top_level.txt,sha256=0kbUVnSHjYxSRD1ziCdpw73ECdl7QysxeNHlRuY9xtc,8
|
24
|
+
tretool-1.0.0.dist-info/RECORD,,
|
tretool/markfunc.py
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
### 标记函数,并在调用时发出提示。
|
3
|
-
##### 例:
|
4
|
-
```
|
5
|
-
@wrapper.deprecated_func(version='1.2.1', alternative='main')
|
6
|
-
def slow():
|
7
|
-
print('slow func')
|
8
|
-
"""
|
9
|
-
|
10
|
-
import functools
|
11
|
-
import warnings
|
12
|
-
import inspect
|
13
|
-
import time
|
14
|
-
|
15
|
-
from typing import Optional, Callable, Any
|
16
|
-
|
17
|
-
|
18
|
-
def info(func: Optional[Callable] = None, *,
|
19
|
-
show_args: bool = True,
|
20
|
-
show_kwargs: bool = True,
|
21
|
-
show_return: bool = True,
|
22
|
-
show_time: bool = True,
|
23
|
-
log_file: Optional[str] = None,
|
24
|
-
indent: int = 0) -> Callable:
|
25
|
-
"""
|
26
|
-
装饰器:输出函数的详细调用信息
|
27
|
-
|
28
|
-
参数:
|
29
|
-
func (Callable): 被装饰的函数(自动传入,无需手动指定)
|
30
|
-
show_args (bool): 是否显示位置参数,默认True
|
31
|
-
show_kwargs (bool): 是否显示关键字参数,默认True
|
32
|
-
show_return (bool): 是否显示返回值,默认True
|
33
|
-
show_time (bool): 是否显示执行时间,默认True
|
34
|
-
log_file (str): 日志文件路径,不指定则输出到stdout
|
35
|
-
indent (int): 缩进空格数,用于嵌套调用时格式化输出
|
36
|
-
|
37
|
-
返回:
|
38
|
-
包装后的函数,调用时会输出详细信息
|
39
|
-
|
40
|
-
示例:
|
41
|
-
```python
|
42
|
-
@info()
|
43
|
-
def add(a, b):
|
44
|
-
return a + b
|
45
|
-
|
46
|
-
@info(show_kwargs=False, log_file="app.log")
|
47
|
-
def greet(name, message="Hello"):
|
48
|
-
return f"{message}, {name}"
|
49
|
-
```
|
50
|
-
"""
|
51
|
-
def decorator(f: Callable) -> Callable:
|
52
|
-
@functools.wraps(f)
|
53
|
-
def wrapper(*args, **kwargs) -> Any:
|
54
|
-
# 准备输出内容
|
55
|
-
output = []
|
56
|
-
indent_str = ' ' * indent
|
57
|
-
|
58
|
-
# 函数基本信息
|
59
|
-
output.append(f"{indent_str}┌── 调用函数: {f.__name__}")
|
60
|
-
|
61
|
-
# 参数信息
|
62
|
-
if show_args and args:
|
63
|
-
sig = inspect.signature(f)
|
64
|
-
params = list(sig.parameters.values())
|
65
|
-
arg_details = []
|
66
|
-
for i, arg in enumerate(args):
|
67
|
-
if i < len(params):
|
68
|
-
param_name = params[i].name
|
69
|
-
arg_details.append(f"{param_name}={repr(arg)}")
|
70
|
-
else:
|
71
|
-
arg_details.append(repr(arg))
|
72
|
-
output.append(f"{indent_str}├── 位置参数: {', '.join(arg_details)}")
|
73
|
-
|
74
|
-
if show_kwargs and kwargs:
|
75
|
-
kwargs_details = [f"{k}={repr(v)}" for k, v in kwargs.items()]
|
76
|
-
output.append(f"{indent_str}├── 关键字参数: {', '.join(kwargs_details)}")
|
77
|
-
|
78
|
-
# 执行函数并计时
|
79
|
-
start_time = time.perf_counter()
|
80
|
-
result = f(*args, **kwargs)
|
81
|
-
elapsed = time.perf_counter() - start_time
|
82
|
-
|
83
|
-
# 返回值和执行时间
|
84
|
-
if show_return:
|
85
|
-
output.append(f"{indent_str}├── 返回值: {repr(result)}")
|
86
|
-
|
87
|
-
if show_time:
|
88
|
-
output.append(f"{indent_str}└── 执行时间: {elapsed:.6f}秒")
|
89
|
-
else:
|
90
|
-
output[-1] = output[-1].replace('├──', '└──')
|
91
|
-
|
92
|
-
# 输出日志
|
93
|
-
log_message = '\n'.join(output)
|
94
|
-
if log_file:
|
95
|
-
with open(log_file, 'a', encoding='utf-8') as f:
|
96
|
-
f.write(log_message + '\n\n')
|
97
|
-
else:
|
98
|
-
print(log_message + '\n')
|
99
|
-
|
100
|
-
return result
|
101
|
-
|
102
|
-
return wrapper
|
103
|
-
|
104
|
-
# 处理带参数和不带参数的装饰器用法
|
105
|
-
if func is None:
|
106
|
-
return decorator
|
107
|
-
else:
|
108
|
-
return decorator(func)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
def deprecated_func(original_func=None, *, reason=None, version=None, alternative=None):
|
113
|
-
"""
|
114
|
-
装饰器:标记函数已弃用,并在调用时发出警告
|
115
|
-
|
116
|
-
参数:
|
117
|
-
reason (str): 弃用的原因说明
|
118
|
-
version (str): 计划移除的版本号
|
119
|
-
alternative (str): 推荐的替代函数或方法
|
120
|
-
|
121
|
-
返回:
|
122
|
-
包装后的函数,调用时会发出弃用警告
|
123
|
-
|
124
|
-
示例:
|
125
|
-
```@deprecated_func(reason="使用新API", version="2.0", alternative="new_function")
|
126
|
-
def old_function():
|
127
|
-
pass
|
128
|
-
"""
|
129
|
-
def decorator(func):
|
130
|
-
@functools.wraps(func)
|
131
|
-
def wrapper(*args, **kwargs):
|
132
|
-
# 构建详细的警告消息
|
133
|
-
message = f"函数 {func.__name__} 已被弃用"
|
134
|
-
if reason:
|
135
|
-
message += f",原因: {reason}"
|
136
|
-
if version:
|
137
|
-
message += f",将在 {version} 版本中移除"
|
138
|
-
if alternative:
|
139
|
-
message += f",请使用 {alternative} 替代"
|
140
|
-
|
141
|
-
# 发出更正式的警告
|
142
|
-
warnings.warn(message, category=DeprecationWarning, stacklevel=2)
|
143
|
-
|
144
|
-
# 执行原始函数
|
145
|
-
return func(*args, **kwargs)
|
146
|
-
return wrapper
|
147
|
-
|
148
|
-
# 处理带参数和不带参数的装饰器用法
|
149
|
-
if original_func is None:
|
150
|
-
return decorator
|
151
|
-
else:
|
152
|
-
return decorator(original_func)
|
tretool/memorizeTools.py
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
### memoize_utils.py - 高级记忆化装饰器工具集
|
3
|
-
|
4
|
-
#### 提供功能强大的缓存装饰器
|
5
|
-
"""
|
6
|
-
|
7
|
-
import functools
|
8
|
-
|
9
|
-
def memorize(func):
|
10
|
-
"""
|
11
|
-
功能强大的缓存装饰器。
|
12
|
-
"""
|
13
|
-
cache = {}
|
14
|
-
|
15
|
-
@functools.wraps(func)
|
16
|
-
def wrapper(*args, **kwargs):
|
17
|
-
key = str(args) + str(kwargs)
|
18
|
-
|
19
|
-
if key not in cache:
|
20
|
-
cache[key] = func(*args, **kwargs)
|
21
|
-
|
22
|
-
return cache[key]
|
23
|
-
|
24
|
-
return wrapper
|
tretool/writeLog.py
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import datetime
|
3
|
-
import traceback
|
4
|
-
|
5
|
-
from typing import Tuple
|
6
|
-
|
7
|
-
class LogWriter:
|
8
|
-
def __init__(self) -> None:
|
9
|
-
self.log = []
|
10
|
-
|
11
|
-
|
12
|
-
def save_file(self, filepath:str) -> Tuple[bool, str]:
|
13
|
-
try:
|
14
|
-
with open(filepath, 'w', encoding='utf-8') as file:
|
15
|
-
file.write('\n'.join(self.log))
|
16
|
-
return (True, 'No error')
|
17
|
-
except Exception as e:
|
18
|
-
return (False, str(e))
|
19
|
-
|
20
|
-
|
21
|
-
def write_debug(self, content:str, user:str='root', time:str=None):
|
22
|
-
if time is None:
|
23
|
-
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
24
|
-
|
25
|
-
self.log.append(f'[{time}] (debug) {user}: {content}')
|
26
|
-
|
27
|
-
|
28
|
-
def write_info(self, content:str, user:str='root', time:str=None):
|
29
|
-
if time is None:
|
30
|
-
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
31
|
-
|
32
|
-
self.log.append(f'[{time}] (info) {user}: {content}')
|
33
|
-
|
34
|
-
|
35
|
-
def write_warning(self, content:str, user:str='root', time:str=None):
|
36
|
-
if time is None:
|
37
|
-
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
38
|
-
|
39
|
-
self.log.append(f'[{time}] (warning) {user}: {content}')
|
40
|
-
|
41
|
-
|
42
|
-
def write_error(self, content:str, user:str='root', time:str=None):
|
43
|
-
if time is None:
|
44
|
-
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
45
|
-
|
46
|
-
self.log.append(f'[{time}] (error) {user}: {content}')
|
47
|
-
|
48
|
-
|
49
|
-
def write_traceback(self, user: str = 'root', time: str = None):
|
50
|
-
"""捕获当前异常信息并写入日志"""
|
51
|
-
if time is None:
|
52
|
-
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
53
|
-
|
54
|
-
# 获取当前异常信息
|
55
|
-
exc_type, exc_value, exc_traceback = sys.exc_info()
|
56
|
-
if exc_type is None: # 如果没有异常,直接返回
|
57
|
-
return
|
58
|
-
|
59
|
-
# 格式化 traceback 信息
|
60
|
-
tb_lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
61
|
-
tb_content = ''.join(tb_lines).strip() # 将 traceback 转为字符串
|
62
|
-
|
63
|
-
# 写入日志
|
64
|
-
self.log.append(f'[{time}] {user}: [EXCEPTION]\n{tb_content}')
|
65
|
-
|
66
|
-
|
67
|
-
@property
|
68
|
-
def log_content(self):
|
69
|
-
return self.log
|
tretool-0.2.1.dist-info/RECORD
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
tretool/__init__.py,sha256=g8doPxAxYQEDb6JTP8KVCuvN0eXlNTT2yS7hodLbKOA,498
|
2
|
-
tretool/config.py,sha256=nWGKFfQbpihFCeVejiyhQ1dpxcw4EC0biAJtkvQRILc,8179
|
3
|
-
tretool/encoding.py,sha256=bED_2D1TXcH0Z7AbBqfeVWrlH7ER99-SngaNi-vlMow,2735
|
4
|
-
tretool/jsonlib.py,sha256=tR51UJg9q_pPdmryoPsdjnuAPun6UESDMyD4Uv4lzMg,9808
|
5
|
-
tretool/markfunc.py,sha256=vv9tdfwRX9MosvFdRFkf-oOysyK6HgFE3UzuYnp0Pc8,5298
|
6
|
-
tretool/mathlib.py,sha256=Lz6UkZM5Gf3x_4RWVRtNiIxLAcQ_Y72h_aGYAVref8g,19696
|
7
|
-
tretool/memorizeTools.py,sha256=OBTV4XHdInduA8O1mUGpP4tE4Ze1h5FqZbPOVDm3s3I,466
|
8
|
-
tretool/path.py,sha256=eEmJL33MiYK3X1n74Jc98YqH3SDOJ09KDnlBCFFaVII,31910
|
9
|
-
tretool/platformlib.py,sha256=XDWo7kf9zwGguFK77yG3T_R4tc-unjdM3dbUA6rZ29o,9727
|
10
|
-
tretool/plugin.py,sha256=OcOmXCrzhiyOjSDSx3lqykJqpyLtbRMOBpEZBz3sUXY,13182
|
11
|
-
tretool/timelib.py,sha256=XH1o8WDoj4W41vO-AuRV782d6IuqvmcCuKEkdabHsjg,16559
|
12
|
-
tretool/writeLog.py,sha256=l-7BtOGCFk1DZNyPI5Vw_EdC_NbgfwKGpHWbdL8Pi9c,2251
|
13
|
-
tretool/plugin/plu.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
tretool/transform/__init__.py,sha256=-0UKgEwky5AAV_UNGSRdKhYbrkAjUHZIO4Lj0z-ITPE,17
|
15
|
-
tretool/transform/pdf.py,sha256=yP__RWZvZt5FmfKubT7Tw1oDf1dKNLi43mB05w2n9z4,14156
|
16
|
-
tretool-0.2.1.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
17
|
-
tretool-0.2.1.dist-info/METADATA,sha256=48L-GCSmZCvG6VCnSTkkQ1xIy4NScYD-5CiTZ7YlI_0,792
|
18
|
-
tretool-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
19
|
-
tretool-0.2.1.dist-info/top_level.txt,sha256=0kbUVnSHjYxSRD1ziCdpw73ECdl7QysxeNHlRuY9xtc,8
|
20
|
-
tretool-0.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|