ErisPulse 2.1.13rc3__py3-none-any.whl → 2.1.14__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.
ErisPulse/Core/raiserr.py DELETED
@@ -1,181 +0,0 @@
1
- """
2
- ErisPulse 错误管理系统
3
-
4
- 提供全局异常捕获功能。不再推荐使用自定义错误注册功能。
5
-
6
- {!--< tips >!--}
7
- 1. 请使用Python原生异常抛出方法
8
- 2. 系统会自动捕获并格式化所有未处理异常
9
- 3. 注册功能已标记为弃用,将在未来版本移除
10
- {!--< /tips >!--}
11
- """
12
-
13
- import sys
14
- import traceback
15
- import asyncio
16
- from typing import Dict, Any, Optional, Type, Callable, List, Set, Tuple, Union
17
-
18
- class Error:
19
- """
20
- 错误管理器
21
-
22
- {!--< deprecated >!--} 请使用Python原生异常抛出方法 | 2025-07-18
23
-
24
- {!--< tips >!--}
25
- 1. 注册功能将在未来版本移除
26
- 2. 请直接使用raise Exception("message")方式抛出异常
27
- {!--< /tips >!--}
28
- """
29
-
30
- def __init__(self):
31
- self._types = {}
32
-
33
- def register(self, name: str, doc: str = "", base: Type[Exception] = Exception) -> Type[Exception]:
34
- """
35
- 注册新的错误类型
36
-
37
- {!--< deprecated >!--} 请使用Python原生异常抛出方法 | 2025-07-18
38
-
39
- :param name: 错误类型名称
40
- :param doc: 错误描述文档
41
- :param base: 基础异常类
42
- :return: 注册的错误类
43
- """
44
- if name not in self._types:
45
- err_cls = type(name, (base,), {"__doc__": doc})
46
- self._types[name] = err_cls
47
- return self._types[name]
48
-
49
- def __getattr__(self, name: str) -> Callable[..., None]:
50
- """
51
- 动态获取错误抛出函数
52
-
53
- {!--< deprecated >!--} 请使用Python原生异常抛出方法 | 2025-07-18
54
-
55
- :param name: 错误类型名称
56
- :return: 错误抛出函数
57
-
58
- :raises AttributeError: 当错误类型未注册时抛出
59
- """
60
- def raiser(msg: str, exit: bool = False) -> None:
61
- """
62
- 错误抛出函数
63
-
64
- :param msg: 错误消息
65
- :param exit: 是否退出程序
66
- """
67
- from .logger import logger
68
- err_cls = self._types.get(name) or self.register(name)
69
- exc = err_cls(msg)
70
-
71
- red = '\033[91m'
72
- reset = '\033[0m'
73
-
74
- logger.error(f"{red}{name}: {msg} | {err_cls.__doc__}{reset}")
75
- logger.error(f"{red}{ ''.join(traceback.format_stack()) }{reset}")
76
-
77
- if exit:
78
- raise exc
79
- return raiser
80
-
81
- def info(self, name: Optional[str] = None) -> Dict[str, Any]:
82
- """
83
- 获取错误信息
84
-
85
- {!--< deprecated >!--} 此功能将在未来版本移除 | 2025-07-18
86
-
87
- :param name: 错误类型名称(可选)
88
- :return: 错误信息字典
89
- """
90
- result = {}
91
- for err_name, err_cls in self._types.items():
92
- result[err_name] = {
93
- "type": err_name,
94
- "doc": getattr(err_cls, "__doc__", ""),
95
- "class": err_cls,
96
- }
97
- if name is None:
98
- return result
99
- err_cls = self._types.get(name)
100
- if not err_cls:
101
- return {
102
- "type": None,
103
- "doc": None,
104
- "class": None,
105
- }
106
- return {
107
- "type": name,
108
- "doc": getattr(err_cls, "__doc__", ""),
109
- "class": err_cls,
110
- }
111
-
112
-
113
- raiserr = Error()
114
-
115
- def global_exception_handler(exc_type: Type[Exception], exc_value: Exception, exc_traceback: Any) -> None:
116
- """
117
- 全局异常处理器
118
-
119
- :param exc_type: 异常类型
120
- :param exc_value: 异常值
121
- :param exc_traceback: 追踪信息
122
- """
123
- RED = '\033[91m'
124
- YELLOW = '\033[93m'
125
- BLUE = '\033[94m'
126
- RESET = '\033[0m'
127
-
128
- error_title = f"{RED}{exc_type.__name__}{RESET}: {YELLOW}{exc_value}{RESET}"
129
- traceback_lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
130
-
131
- colored_traceback = []
132
- for line in traceback_lines:
133
- if "File " in line and ", line " in line:
134
- parts = line.split(', line ')
135
- colored_line = f"{BLUE}{parts[0]}{RESET}, line {parts[1]}"
136
- colored_traceback.append(colored_line)
137
- else:
138
- colored_traceback.append(f"{RED}{line}{RESET}")
139
-
140
- full_error = f"""
141
- {error_title}
142
- {RED}Traceback:{RESET}
143
- {colored_traceback}"""
144
-
145
- sys.stderr.write(full_error)
146
-
147
- def async_exception_handler(loop: asyncio.AbstractEventLoop, context: Dict[str, Any]) -> None:
148
- """
149
- 异步异常处理器
150
-
151
- :param loop: 事件循环
152
- :param context: 上下文字典
153
- """
154
- RED = '\033[91m'
155
- YELLOW = '\033[93m'
156
- BLUE = '\033[94m'
157
- RESET = '\033[0m'
158
-
159
- exception = context.get('exception')
160
- if exception:
161
- tb = ''.join(traceback.format_exception(type(exception), exception, exception.__traceback__))
162
-
163
- colored_tb = []
164
- for line in tb.split('\n'):
165
- if "File " in line and ", line " in line:
166
- parts = line.split(', line ')
167
- colored_line = f"{BLUE}{parts[0]}{RESET}, line {parts[1]}"
168
- colored_tb.append(colored_line)
169
- else:
170
- colored_tb.append(f"{RED}{line}{RESET}")
171
-
172
- error_msg = f"""{RED}{type(exception).__name__}{RESET}: {YELLOW}{exception}{RESET}
173
- {RED}Traceback:{RESET}
174
- {colored_tb}"""
175
- sys.stderr.write(error_msg)
176
- else:
177
- msg = context.get('message', 'Unknown async error')
178
- sys.stderr.write(f"{RED}Async Error{RESET}: {YELLOW}{msg}{RESET}")
179
-
180
- sys.excepthook = global_exception_handler
181
- asyncio.get_event_loop().set_exception_handler(async_exception_handler)
ErisPulse/Core/util.py DELETED
@@ -1,123 +0,0 @@
1
- """
2
- ErisPulse 工具函数集合
3
-
4
- 提供常用工具函数,包括拓扑排序、缓存装饰器、异步执行等实用功能。
5
-
6
- {!--< tips >!--}
7
- 1. 使用@cache装饰器缓存函数结果
8
- 2. 使用@run_in_executor在独立线程中运行同步函数
9
- 3. 使用@retry实现自动重试机制
10
- {!--< /tips >!--}
11
- """
12
-
13
- import time
14
- import asyncio
15
- import functools
16
- import traceback
17
- from concurrent.futures import ThreadPoolExecutor
18
- from collections import defaultdict, deque
19
- from typing import List, Dict, Type, Callable, Any, Optional, Set
20
-
21
- executor = ThreadPoolExecutor()
22
-
23
- class Util:
24
- """
25
- 工具函数集合
26
-
27
- 提供各种实用功能,简化开发流程
28
-
29
- {!--< tips >!--}
30
- 1. 拓扑排序用于解决依赖关系
31
- 2. 装饰器简化常见模式实现
32
- 3. 异步执行提升性能
33
- {!--< /tips >!--}
34
- """
35
- def ExecAsync(self, async_func: Callable, *args: Any, **kwargs: Any) -> Any:
36
- """
37
- 异步执行函数
38
-
39
- :param async_func: 异步函数
40
- :param args: 位置参数
41
- :param kwargs: 关键字参数
42
- :return: 函数执行结果
43
-
44
- :example:
45
- >>> result = util.ExecAsync(my_async_func, arg1, arg2)
46
- """
47
- loop = asyncio.get_event_loop()
48
- return loop.run_in_executor(executor, lambda: asyncio.run(async_func(*args, **kwargs)))
49
-
50
- def cache(self, func: Callable) -> Callable:
51
- """
52
- 缓存装饰器
53
-
54
- :param func: 被装饰函数
55
- :return: 装饰后的函数
56
-
57
- :example:
58
- >>> @util.cache
59
- >>> def expensive_operation(param):
60
- >>> return heavy_computation(param)
61
- """
62
- cache_dict = {}
63
- @functools.wraps(func)
64
- def wrapper(*args, **kwargs):
65
- key = (args, tuple(sorted(kwargs.items())))
66
- if key not in cache_dict:
67
- cache_dict[key] = func(*args, **kwargs)
68
- return cache_dict[key]
69
- return wrapper
70
-
71
- def run_in_executor(self, func: Callable) -> Callable:
72
- """
73
- 在独立线程中执行同步函数的装饰器
74
-
75
- :param func: 被装饰的同步函数
76
- :return: 可等待的协程函数
77
-
78
- :example:
79
- >>> @util.run_in_executor
80
- >>> def blocking_io():
81
- >>> # 执行阻塞IO操作
82
- >>> return result
83
- """
84
- @functools.wraps(func)
85
- async def wrapper(*args, **kwargs):
86
- loop = asyncio.get_event_loop()
87
- try:
88
- return await loop.run_in_executor(None, lambda: func(*args, **kwargs))
89
- except Exception as e:
90
- from . import logger
91
- logger.error(f"线程内发生未处理异常:\n{''.join(traceback.format_exc())}")
92
- return wrapper
93
-
94
- def retry(self, max_attempts: int = 3, delay: int = 1) -> Callable:
95
- """
96
- 自动重试装饰器
97
-
98
- :param max_attempts: 最大重试次数 (默认: 3)
99
- :param delay: 重试间隔(秒) (默认: 1)
100
- :return: 装饰器函数
101
-
102
- :example:
103
- >>> @util.retry(max_attempts=5, delay=2)
104
- >>> def unreliable_operation():
105
- >>> # 可能失败的操作
106
- """
107
- def decorator(func: Callable) -> Callable:
108
- @functools.wraps(func)
109
- def wrapper(*args, **kwargs):
110
- attempts = 0
111
- while attempts < max_attempts:
112
- try:
113
- return func(*args, **kwargs)
114
- except Exception as e:
115
- attempts += 1
116
- if attempts == max_attempts:
117
- raise
118
- time.sleep(delay)
119
- return wrapper
120
- return decorator
121
-
122
-
123
- util = Util()
@@ -1,16 +0,0 @@
1
- ErisPulse/__init__.py,sha256=T-N56UQyBmpvlqwH2wGi5ptPzaJpbgF5tKkJt0DlkaM,26099
2
- ErisPulse/__main__.py,sha256=kGpk-BeztjhrdNwWL2mZxaVy05y4XicCS6SZGtQERho,37409
3
- ErisPulse/Core/__init__.py,sha256=tBYPahQ7-w7U6M69xy8DW0_ECa9ja-Q0y_SQqVswYBo,409
4
- ErisPulse/Core/adapter.py,sha256=ZK81dibJ471FowL0MRXkS113iBcMgj_VzpTw0PzhAEo,18102
5
- ErisPulse/Core/config.py,sha256=ZmwGdtHSOE7K5uOGzLYcyl3ZF3sAmeWAntqcdfDzhpM,5027
6
- ErisPulse/Core/env.py,sha256=HGkzsdbxh8c1GSDJhnGP9B09Sz2ZeNbRxWieaFmAcug,18870
7
- ErisPulse/Core/logger.py,sha256=cJzNXF-EmdWxwgiHg5Itmkwsva2Jhe9l9X4rXKiXHgc,8296
8
- ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
9
- ErisPulse/Core/raiserr.py,sha256=vlyaaiOIYkyqm9dAqSW9E54JBzX-9roHDp5_r6I0yUU,5591
10
- ErisPulse/Core/server.py,sha256=FkDTeLuHD5IBnWVxvYU8pHb6yCt8GzyvC1bpOiJ7G7I,9217
11
- ErisPulse/Core/util.py,sha256=7rdMmn6sBFqYd4znxBCcJjuv2eyTExdeKyZopgds868,3796
12
- erispulse-2.1.13rc3.dist-info/METADATA,sha256=ppMW2h_uDFhvpfP9u30vbaHgQA9fr_oPdDzeWaLQRf4,6262
13
- erispulse-2.1.13rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- erispulse-2.1.13rc3.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
15
- erispulse-2.1.13rc3.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
16
- erispulse-2.1.13rc3.dist-info/RECORD,,