ErisPulse 2.3.3.dev0__py3-none-any.whl → 2.3.4.dev2__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.
Files changed (97) hide show
  1. ErisPulse/CLI/__init__.py +11 -0
  2. ErisPulse/CLI/__init__.pyi +13 -0
  3. ErisPulse/CLI/base.py +52 -0
  4. ErisPulse/CLI/base.pyi +50 -0
  5. ErisPulse/CLI/cli.py +224 -0
  6. ErisPulse/CLI/cli.pyi +80 -0
  7. ErisPulse/CLI/commands/__init__.py +6 -0
  8. ErisPulse/CLI/commands/__init__.pyi +12 -0
  9. ErisPulse/CLI/commands/init.py +395 -0
  10. ErisPulse/CLI/commands/init.pyi +70 -0
  11. ErisPulse/CLI/commands/install.py +302 -0
  12. ErisPulse/CLI/commands/install.pyi +58 -0
  13. ErisPulse/CLI/commands/list.py +160 -0
  14. ErisPulse/CLI/commands/list.pyi +44 -0
  15. ErisPulse/CLI/commands/list_remote.py +123 -0
  16. ErisPulse/CLI/commands/list_remote.pyi +35 -0
  17. ErisPulse/CLI/commands/run.py +108 -0
  18. ErisPulse/CLI/commands/run.pyi +39 -0
  19. ErisPulse/CLI/commands/self_update.py +232 -0
  20. ErisPulse/CLI/commands/self_update.pyi +47 -0
  21. ErisPulse/CLI/commands/uninstall.py +32 -0
  22. ErisPulse/CLI/commands/uninstall.pyi +24 -0
  23. ErisPulse/CLI/commands/upgrade.py +56 -0
  24. ErisPulse/CLI/commands/upgrade.pyi +25 -0
  25. ErisPulse/CLI/console.pyi +20 -0
  26. ErisPulse/CLI/registry.py +112 -0
  27. ErisPulse/CLI/registry.pyi +99 -0
  28. ErisPulse/{utils → CLI/utils}/__init__.py +2 -6
  29. ErisPulse/CLI/utils/__init__.pyi +14 -0
  30. ErisPulse/{utils → CLI/utils}/package_manager.py +146 -20
  31. ErisPulse/CLI/utils/package_manager.pyi +241 -0
  32. ErisPulse/{utils → CLI/utils}/reload_handler.py +7 -8
  33. ErisPulse/CLI/utils/reload_handler.pyi +64 -0
  34. ErisPulse/Core/Bases/__init__.pyi +14 -0
  35. ErisPulse/Core/Bases/adapter.py +13 -1
  36. ErisPulse/Core/Bases/adapter.pyi +140 -0
  37. ErisPulse/Core/Bases/manager.py +136 -0
  38. ErisPulse/Core/Bases/manager.pyi +108 -0
  39. ErisPulse/Core/Bases/module.py +53 -1
  40. ErisPulse/Core/Bases/module.pyi +95 -0
  41. ErisPulse/Core/Event/__init__.pyi +26 -0
  42. ErisPulse/Core/Event/base.pyi +62 -0
  43. ErisPulse/Core/Event/command.py +6 -1
  44. ErisPulse/Core/Event/command.pyi +113 -0
  45. ErisPulse/Core/Event/exceptions.pyi +43 -0
  46. ErisPulse/Core/Event/message.pyi +93 -0
  47. ErisPulse/Core/Event/meta.pyi +92 -0
  48. ErisPulse/Core/Event/notice.pyi +108 -0
  49. ErisPulse/Core/Event/request.pyi +76 -0
  50. ErisPulse/Core/Event/wrapper.py +2 -3
  51. ErisPulse/Core/Event/wrapper.pyi +403 -0
  52. ErisPulse/Core/__init__.py +16 -13
  53. ErisPulse/Core/__init__.pyi +16 -0
  54. ErisPulse/Core/_self_config.py +1 -1
  55. ErisPulse/Core/_self_config.pyi +72 -0
  56. ErisPulse/Core/adapter.py +70 -10
  57. ErisPulse/Core/adapter.pyi +246 -0
  58. ErisPulse/Core/config.pyi +70 -0
  59. ErisPulse/Core/exceptions.py +4 -2
  60. ErisPulse/Core/exceptions.pyi +60 -0
  61. ErisPulse/Core/lifecycle.py +15 -1
  62. ErisPulse/Core/lifecycle.pyi +92 -0
  63. ErisPulse/Core/logger.py +21 -15
  64. ErisPulse/Core/logger.pyi +169 -0
  65. ErisPulse/Core/module.py +57 -9
  66. ErisPulse/Core/module.pyi +189 -0
  67. ErisPulse/Core/router.py +13 -5
  68. ErisPulse/Core/router.pyi +120 -0
  69. ErisPulse/Core/storage.py +94 -256
  70. ErisPulse/Core/storage.pyi +220 -0
  71. ErisPulse/__init__.py +35 -1236
  72. ErisPulse/__init__.pyi +22 -0
  73. ErisPulse/__main__.py +1 -1
  74. ErisPulse/__main__.pyi +24 -0
  75. ErisPulse/loaders/__init__.py +22 -0
  76. ErisPulse/loaders/__init__.pyi +21 -0
  77. ErisPulse/loaders/adapter_loader.py +187 -0
  78. ErisPulse/loaders/adapter_loader.pyi +82 -0
  79. ErisPulse/loaders/base_loader.py +162 -0
  80. ErisPulse/loaders/base_loader.pyi +23 -0
  81. ErisPulse/loaders/initializer.py +150 -0
  82. ErisPulse/loaders/initializer.pyi +60 -0
  83. ErisPulse/loaders/module_loader.py +618 -0
  84. ErisPulse/loaders/module_loader.pyi +179 -0
  85. ErisPulse/loaders/strategy.py +129 -0
  86. ErisPulse/loaders/strategy.pyi +90 -0
  87. ErisPulse/sdk.py +435 -0
  88. ErisPulse/sdk.pyi +158 -0
  89. {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/METADATA +6 -20
  90. erispulse-2.3.4.dev2.dist-info/RECORD +103 -0
  91. {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/licenses/LICENSE +3 -3
  92. ErisPulse/Core/ux.py +0 -635
  93. ErisPulse/utils/cli.py +0 -1097
  94. erispulse-2.3.3.dev0.dist-info/RECORD +0 -35
  95. /ErisPulse/{utils → CLI}/console.py +0 -0
  96. {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/WHEEL +0 -0
  97. {erispulse-2.3.3.dev0.dist-info → erispulse-2.3.4.dev2.dist-info}/entry_points.txt +0 -0
@@ -1,12 +1,11 @@
1
- from .lifecycle import lifecycle
2
- from .adapter import adapter
1
+ from .lifecycle import lifecycle, LifecycleManager
2
+ from .adapter import adapter, AdapterManager
3
3
  from .Bases import BaseAdapter, BaseModule, SendDSL
4
- from .storage import storage
5
- from .logger import logger
6
- from .module import module
7
- from .router import router
8
- from .config import config
9
- from .ux import ux, UXManager
4
+ from .storage import storage, StorageManager
5
+ from .logger import logger, Logger, LoggerChild
6
+ from .module import module, ModuleManager
7
+ from .router import router, RouterManager
8
+ from .config import config, ConfigManager
10
9
  from . import exceptions
11
10
  from . import Event
12
11
 
@@ -21,29 +20,33 @@ __all__ = [
21
20
 
22
21
  # 适配器相关
23
22
  'adapter', # 适配器管理器
23
+ 'AdapterManager', # 适配器管理器类
24
24
  'AdapterFather', # 适配器基类
25
25
  'BaseAdapter', # 适配器基类别名
26
26
  'SendDSL', # DSL发送接口基类
27
27
 
28
28
  # 模块相关
29
29
  'module', # 模块管理器
30
+ 'ModuleManager', # 模块管理器类
30
31
  'BaseModule', # 模块基类
31
32
 
32
33
  # 存储和配置相关
33
34
  'storage', # 存储管理器
35
+ 'StorageManager', # 存储管理器类
34
36
  'config', # 配置管理器
37
+ 'ConfigManager', # 配置管理器类
35
38
  'env', # 配置管理器别名
36
39
 
37
40
  # 路由相关
38
41
  'router', # 路由管理器
42
+ 'RouterManager', # 路由管理器类
39
43
  'adapter_server', # 路由管理器别名
40
44
 
41
- # UX
42
- 'ux', # UX管理器实例
43
- 'UXManager', # UX管理器类
44
-
45
45
  # 基础设施
46
46
  'logger', # 日志管理器
47
+ 'Logger', # 日志管理器类
48
+ 'LoggerChild', # 日志子管理器类
47
49
  'exceptions', # 异常处理模块
48
- 'lifecycle' # 生命周期管理器
50
+ 'lifecycle', # 生命周期管理器
51
+ 'LifecycleManager', # 生命周期管理器类
49
52
  ]
@@ -0,0 +1,16 @@
1
+ # type: ignore
2
+ #
3
+ # Auto-generated type stub for __init__.py
4
+ # DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
5
+ #
6
+
7
+ from .lifecycle import lifecycle, LifecycleManager
8
+ from .adapter import adapter, AdapterManager
9
+ from .Bases import BaseAdapter, BaseModule, SendDSL
10
+ from .storage import storage, StorageManager
11
+ from .logger import logger, Logger, LoggerChild
12
+ from .module import module, ModuleManager
13
+ from .router import router, RouterManager
14
+ from .config import config, ConfigManager
15
+ from . import exceptions
16
+ from . import Event
@@ -21,7 +21,7 @@ DEFAULT_ERISPULSE_CONFIG = {
21
21
  "memory_limit": 1000
22
22
  },
23
23
  "storage": {
24
- "max_snapshot": 20
24
+ "use_global_db": False,
25
25
  },
26
26
  "modules": {},
27
27
  "adapters": {},
@@ -0,0 +1,72 @@
1
+ # type: ignore
2
+ #
3
+ # Auto-generated type stub for _self_config.py
4
+ # DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
5
+ #
6
+
7
+ """
8
+ ErisPulse 框架配置管理
9
+
10
+ 专门管理 ErisPulse 框架自身的配置项。
11
+ """
12
+
13
+ from typing import Dict, Any
14
+ from .config import config
15
+
16
+ def _ensure_erispulse_config_structure(config_dict: Dict[(str, Any)]) -> Dict[(str, Any)]:
17
+ """
18
+ 确保 ErisPulse 配置结构完整,补全缺失的配置项
19
+
20
+ :param config_dict: 当前配置
21
+ :return: 补全后的完整配置
22
+ """
23
+ ...
24
+
25
+ def get_erispulse_config() -> Dict[(str, Any)]:
26
+ """
27
+ 获取 ErisPulse 框架配置,自动补全缺失的配置项并保存
28
+
29
+ :return: 完整的 ErisPulse 配置字典
30
+ """
31
+ ...
32
+
33
+ def update_erispulse_config(new_config: Dict[(str, Any)]) -> bool:
34
+ """
35
+ 更新 ErisPulse 配置,自动补全缺失的配置项
36
+
37
+ :param new_config: 新的配置字典
38
+ :return: 是否更新成功
39
+ """
40
+ ...
41
+
42
+ def get_server_config() -> Dict[(str, Any)]:
43
+ """
44
+ 获取服务器配置,确保结构完整
45
+
46
+ :return: 服务器配置字典
47
+ """
48
+ ...
49
+
50
+ def get_logger_config() -> Dict[(str, Any)]:
51
+ """
52
+ 获取日志配置,确保结构完整
53
+
54
+ :return: 日志配置字典
55
+ """
56
+ ...
57
+
58
+ def get_storage_config() -> Dict[(str, Any)]:
59
+ """
60
+ 获取存储模块配置
61
+
62
+ :return: 存储配置字典
63
+ """
64
+ ...
65
+
66
+ def get_framework_config() -> Dict[(str, Any)]:
67
+ """
68
+ 获取框架配置
69
+
70
+ :return: 框架配置字典
71
+ """
72
+ ...
ErisPulse/Core/adapter.py CHANGED
@@ -14,8 +14,9 @@ from .logger import logger
14
14
  from .Bases.adapter import BaseAdapter
15
15
  from .config import config
16
16
  from .lifecycle import lifecycle
17
+ from .Bases.manager import ManagerBase
17
18
 
18
- class AdapterManager:
19
+ class AdapterManager(ManagerBase):
19
20
  """
20
21
  适配器管理器
21
22
 
@@ -269,6 +270,9 @@ class AdapterManager:
269
270
  from .router import router
270
271
  await router.stop()
271
272
 
273
+ # 清空已启动实例集合
274
+ self._started_instances.clear()
275
+
272
276
  # 提交适配器关闭完成事件
273
277
  await lifecycle.submit_event(
274
278
  "adapter.stopped",
@@ -301,9 +305,8 @@ class AdapterManager:
301
305
  :param platform: 平台名称
302
306
  :return: [bool] 平台是否存在
303
307
  """
304
- # 检查平台是否在配置中注册
305
- adapter_statuses = config.getConfig("ErisPulse.adapters.status", {})
306
- return platform in adapter_statuses
308
+ # 检查平台是否已注册(在 _adapters 中)
309
+ return platform in self._adapters
307
310
 
308
311
  def is_enabled(self, platform: str) -> bool:
309
312
  """
@@ -332,10 +335,11 @@ class AdapterManager:
332
335
  :param platform: 平台名称
333
336
  :return: [bool] 操作是否成功
334
337
  """
335
- if not self.exists(platform):
338
+ # 启用平台时自动在配置中注册
339
+ if platform not in self._adapters:
336
340
  logger.error(f"平台 {platform} 不存在")
337
341
  return False
338
-
342
+
339
343
  config.setConfig(f"ErisPulse.adapters.status.{platform}", True)
340
344
  logger.info(f"平台 {platform} 已启用")
341
345
  return True
@@ -347,21 +351,77 @@ class AdapterManager:
347
351
  :param platform: 平台名称
348
352
  :return: [bool] 操作是否成功
349
353
  """
350
- if not self.exists(platform):
354
+ # 禁用平台时自动在配置中注册
355
+ if platform not in self._adapters:
351
356
  logger.error(f"平台 {platform} 不存在")
352
357
  return False
353
-
358
+
354
359
  config.setConfig(f"ErisPulse.adapters.status.{platform}", False)
355
360
  logger.info(f"平台 {platform} 已禁用")
356
361
  return True
357
362
 
363
+ def unregister(self, platform: str) -> bool:
364
+ """
365
+ 取消注册适配器
366
+
367
+ :param platform: 平台名称
368
+ :return: 是否取消成功
369
+
370
+ {!--< internal-use >!--}
371
+ 注意:此方法仅取消注册,不关闭已启动的适配器
372
+ {!--< /internal-use >!--}
373
+ """
374
+ if platform not in self._adapters:
375
+ logger.warning(f"平台 {platform} 未注册")
376
+ return False
377
+
378
+ # 移除适配器实例
379
+ adapter = self._adapters.pop(platform)
380
+
381
+ # 移除平台属性
382
+ if len(platform) <= 10:
383
+ from itertools import product
384
+ combinations = [''.join(c) for c in product(*[(ch.lower(), ch.upper()) for ch in platform])]
385
+ for name in set(combinations):
386
+ if hasattr(self, name):
387
+ delattr(self, name)
388
+ else:
389
+ if hasattr(self, platform.lower()):
390
+ delattr(self, platform.lower())
391
+ if hasattr(self, platform.upper()):
392
+ delattr(self, platform.upper())
393
+ if hasattr(self, platform.capitalize()):
394
+ delattr(self, platform.capitalize())
395
+
396
+ logger.info(f"平台 {platform} 已取消注册")
397
+ return True
398
+
399
+ def list_registered(self) -> List[str]:
400
+ """
401
+ 列出所有已注册的平台
402
+
403
+ :return: 平台名称列表
404
+ """
405
+ return list(self._adapters.keys())
406
+
407
+ def list_items(self) -> Dict[str, bool]:
408
+ """
409
+ 列出所有平台适配器状态
410
+
411
+ :return: {平台名: 是否启用} 字典
412
+ """
413
+ return config.getConfig("ErisPulse.adapters.status", {})
414
+
415
+ # 兼容性方法 - 保持向后兼容
358
416
  def list_adapters(self) -> Dict[str, bool]:
359
417
  """
360
418
  列出所有平台适配器状态
361
-
419
+
420
+ {!--< deprecated >!--} 请使用 list_items() 代替
421
+
362
422
  :return: [Dict[str, bool]] 平台适配器状态字典
363
423
  """
364
- return config.getConfig("ErisPulse.adapters.status", {})
424
+ return self.list_items()
365
425
 
366
426
  # ==================== 事件处理与消息发送 ====================
367
427
 
@@ -0,0 +1,246 @@
1
+ # type: ignore
2
+ #
3
+ # Auto-generated type stub for adapter.py
4
+ # DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
5
+ #
6
+
7
+ """
8
+ ErisPulse 适配器系统
9
+
10
+ 提供平台适配器管理功能。支持多平台消息处理、事件驱动和生命周期管理。
11
+ """
12
+
13
+ import functools
14
+ import asyncio
15
+ from typing import Callable, Any, Dict, List, Type, Optional, Set
16
+ from collections import defaultdict
17
+ from .logger import logger
18
+ from .Bases.adapter import BaseAdapter
19
+ from .config import config
20
+ from .lifecycle import lifecycle
21
+ from .Bases.manager import ManagerBase
22
+
23
+ class AdapterManager(ManagerBase):
24
+ """
25
+ 适配器管理器
26
+
27
+ 管理多个平台适配器的注册、启动和关闭,提供与模块管理器一致的接口
28
+
29
+ {!--< tips >!--}
30
+ 1. 通过register方法注册适配器
31
+ 2. 通过startup方法启动适配器
32
+ 3. 通过shutdown方法关闭所有适配器
33
+ 4. 通过on装饰器注册OneBot12协议事件处理器
34
+ {!--< /tips >!--}
35
+ """
36
+ def __init__(self: None) -> ...:
37
+ ...
38
+ def register(self: object, platform: str, adapter_class: Type[BaseAdapter], adapter_info: Optional[Dict] = ...) -> bool:
39
+ """
40
+ 注册新的适配器类(标准化注册方法)
41
+
42
+ :param platform: 平台名称
43
+ :param adapter_class: 适配器类
44
+ :param adapter_info: 适配器信息
45
+ :return: 注册是否成功
46
+
47
+ :raises TypeError: 当适配器类无效时抛出
48
+
49
+ :example:
50
+ >>> adapter.register("MyPlatform", MyPlatformAdapter)
51
+ """
52
+ ...
53
+ def _register_platform_attributes(self: object, platform: str, instance: BaseAdapter) -> None:
54
+ """
55
+ 注册平台名称的多种大小写形式作为属性
56
+
57
+ :param platform: 平台名称
58
+ :param instance: 适配器实例
59
+ """
60
+ ...
61
+ async def startup(self: object, platforms: ... = ...) -> None:
62
+ """
63
+ 启动指定的适配器
64
+
65
+ :param platforms: 要启动的平台列表,None表示所有平台
66
+
67
+ :raises ValueError: 当平台未注册时抛出
68
+
69
+ :example:
70
+ >>> # 启动所有适配器
71
+ >>> await adapter.startup()
72
+ >>> # 启动指定适配器
73
+ >>> await adapter.startup(["Platform1", "Platform2"])
74
+ """
75
+ ...
76
+ async def shutdown(self: object) -> None:
77
+ """
78
+ 关闭所有适配器
79
+ """
80
+ ...
81
+ def _config_register(self: object, platform: str, enabled: bool = ...) -> bool:
82
+ """
83
+ 注册新平台适配器(仅当平台不存在时注册)
84
+
85
+ :param platform: 平台名称
86
+ :param enabled: [bool] 是否启用适配器
87
+ :return: [bool] 操作是否成功
88
+ """
89
+ ...
90
+ def exists(self: object, platform: str) -> bool:
91
+ """
92
+ 检查平台是否存在
93
+
94
+ :param platform: 平台名称
95
+ :return: [bool] 平台是否存在
96
+ """
97
+ ...
98
+ def is_enabled(self: object, platform: str) -> bool:
99
+ """
100
+ 检查平台适配器是否启用
101
+
102
+ :param platform: 平台名称
103
+ :return: [bool] 平台适配器是否启用
104
+ """
105
+ ...
106
+ def enable(self: object, platform: str) -> bool:
107
+ """
108
+ 启用平台适配器
109
+
110
+ :param platform: 平台名称
111
+ :return: [bool] 操作是否成功
112
+ """
113
+ ...
114
+ def disable(self: object, platform: str) -> bool:
115
+ """
116
+ 禁用平台适配器
117
+
118
+ :param platform: 平台名称
119
+ :return: [bool] 操作是否成功
120
+ """
121
+ ...
122
+ def list_registered(self: object) -> List[str]:
123
+ """
124
+ 列出所有已注册的平台
125
+
126
+ :return: 平台名称列表
127
+ """
128
+ ...
129
+ def list_items(self: object) -> Dict[(str, bool)]:
130
+ """
131
+ 列出所有平台适配器状态
132
+
133
+ :return: {平台名: 是否启用} 字典
134
+ """
135
+ ...
136
+ def list_adapters(self: object) -> Dict[(str, bool)]:
137
+ """
138
+ 列出所有平台适配器状态
139
+
140
+ {!--< deprecated >!--} 请使用 list_items() 代替
141
+
142
+ :return: [Dict[str, bool]] 平台适配器状态字典
143
+ """
144
+ ...
145
+ def on(self: object, event_type: str = ...) -> Callable[([Callable], Callable)]:
146
+ """
147
+ OneBot12协议事件监听装饰器
148
+
149
+ :param event_type: OneBot12事件类型
150
+ :param raw: 是否监听原生事件
151
+ :param platform: 指定平台,None表示监听所有平台
152
+ :return: 装饰器函数
153
+
154
+ :example:
155
+ >>> # 监听OneBot12标准事件(所有平台)
156
+ >>> @sdk.adapter.on("message")
157
+ >>> async def handle_message(data):
158
+ >>> print(f"收到OneBot12消息: {data}")
159
+ >>>
160
+ >>> # 监听特定平台的OneBot12标准事件
161
+ >>> @sdk.adapter.on("message", platform="onebot11")
162
+ >>> async def handle_onebot11_message(data):
163
+ >>> print(f"收到OneBot11标准消息: {data}")
164
+ >>>
165
+ >>> # 监听平台原生事件
166
+ >>> @sdk.adapter.on("message", raw=True, platform="onebot11")
167
+ >>> async def handle_raw_message(data):
168
+ >>> print(f"收到OneBot11原生事件: {data}")
169
+ >>>
170
+ >>> # 监听所有平台的原生事件
171
+ >>> @sdk.adapter.on("message", raw=True)
172
+ >>> async def handle_all_raw_message(data):
173
+ >>> print(f"收到原生事件: {data}")
174
+ """
175
+ ...
176
+ def middleware(self: object, func: Callable) -> Callable:
177
+ """
178
+ 添加OneBot12中间件处理器
179
+
180
+ :param func: 中间件函数
181
+ :return: 中间件函数
182
+
183
+ :example:
184
+ >>> @sdk.adapter.middleware
185
+ >>> async def onebot_middleware(data):
186
+ >>> print("处理OneBot12数据:", data)
187
+ >>> return data
188
+ """
189
+ ...
190
+ async def emit(self: object, data: Any) -> None:
191
+ """
192
+ 提交OneBot12协议事件到指定平台
193
+
194
+ :param data: 符合OneBot12标准的事件数据
195
+
196
+ :example:
197
+ >>> await sdk.adapter.emit({
198
+ >>> "id": "123",
199
+ >>> "time": 1620000000,
200
+ >>> "type": "message",
201
+ >>> "detail_type": "private",
202
+ >>> "message": [{"type": "text", "data": {"text": "Hello"}}],
203
+ >>> "platform": "myplatform",
204
+ >>> "myplatform_raw": {...平台原生事件数据...},
205
+ >>> "myplatform_raw_type": "text_message"
206
+ >>> })
207
+ """
208
+ ...
209
+ def get(self: object, platform: str) -> Optional[BaseAdapter]:
210
+ """
211
+ 获取指定平台的适配器实例
212
+
213
+ :param platform: 平台名称
214
+ :return: 适配器实例或None
215
+
216
+ :example:
217
+ >>> adapter = adapter.get("MyPlatform")
218
+ """
219
+ ...
220
+ def platforms(self: object) -> List[str]:
221
+ """
222
+ 获取所有已注册的平台列表
223
+
224
+ :return: 平台名称列表
225
+
226
+ :example:
227
+ >>> print("已注册平台:", adapter.platforms)
228
+ """
229
+ ...
230
+ def __getattr__(self: object, platform: str) -> BaseAdapter:
231
+ """
232
+ 通过属性访问获取适配器实例
233
+
234
+ :param platform: 平台名称
235
+ :return: 适配器实例
236
+ :raises AttributeError: 当平台不存在或未启用时
237
+ """
238
+ ...
239
+ def __contains__(self: object, platform: str) -> bool:
240
+ """
241
+ 检查平台是否存在且处于启用状态
242
+
243
+ :param platform: 平台名称
244
+ :return: [bool] 平台是否存在且启用
245
+ """
246
+ ...
@@ -0,0 +1,70 @@
1
+ # type: ignore
2
+ #
3
+ # Auto-generated type stub for config.py
4
+ # DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
5
+ #
6
+
7
+ """
8
+ ErisPulse 配置中心
9
+
10
+ 集中管理所有配置项,避免循环导入问题
11
+ 提供自动补全缺失配置项的功能
12
+ 添加内存缓存和延迟写入机制以提高性能
13
+ """
14
+
15
+ import os
16
+ import time
17
+ import toml
18
+ import threading
19
+ from typing import Any, Dict
20
+
21
+ class ConfigManager:
22
+ def __init__(self: None, config_file: str = ...) -> ...:
23
+ ...
24
+ def _load_config(self: object) -> None:
25
+ """
26
+ 从文件加载配置到缓存
27
+ """
28
+ ...
29
+ def _flush_config(self: object) -> None:
30
+ """
31
+ 将待写入的配置刷新到文件
32
+ """
33
+ ...
34
+ def _schedule_write(self: object) -> None:
35
+ """
36
+ 安排延迟写入
37
+ """
38
+ ...
39
+ def _check_cache_validity(self: object) -> None:
40
+ """
41
+ 检查缓存有效性,必要时重新加载
42
+ """
43
+ ...
44
+ def getConfig(self: object, key: str, default: Any = ...) -> Any:
45
+ """
46
+ 获取模块/适配器配置项(优先从缓存获取)
47
+ :param key: 配置项的键(支持点分隔符如"module.sub.key")
48
+ :param default: 默认值
49
+ :return: 配置项的值
50
+ """
51
+ ...
52
+ def setConfig(self: object, key: str, value: Any, immediate: bool = ...) -> bool:
53
+ """
54
+ 设置模块/适配器配置(缓存+延迟写入)
55
+ :param key: 配置项键名(支持点分隔符如"module.sub.key")
56
+ :param value: 配置项值
57
+ :param immediate: 是否立即写入磁盘(默认为False,延迟写入)
58
+ :return: 操作是否成功
59
+ """
60
+ ...
61
+ def force_save(self: object) -> None:
62
+ """
63
+ 强制立即保存所有待写入的配置到磁盘
64
+ """
65
+ ...
66
+ def reload(self: object) -> None:
67
+ """
68
+ 重新从磁盘加载配置,丢弃所有未保存的更改
69
+ """
70
+ ...
@@ -108,6 +108,8 @@ def setup_async_loop(loop: asyncio.AbstractEventLoop = None) -> None: # type:
108
108
 
109
109
  sys.excepthook = global_exception_handler
110
110
  try:
111
- asyncio.get_event_loop().set_exception_handler(async_exception_handler)
111
+ loop = asyncio.get_running_loop()
112
+ loop.set_exception_handler(async_exception_handler)
112
113
  except RuntimeError:
113
- pass
114
+ # 没有运行中的事件循环,这是正常的,在运行时再设置
115
+ pass
@@ -0,0 +1,60 @@
1
+ # type: ignore
2
+ #
3
+ # Auto-generated type stub for exceptions.py
4
+ # DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
5
+ #
6
+
7
+ """
8
+ ErisPulse 全局异常处理系统
9
+
10
+ 提供统一的异常捕获和格式化功能,支持同步和异步代码的异常处理。
11
+ """
12
+
13
+ import sys
14
+ import traceback
15
+ import asyncio
16
+ import os
17
+ from typing import Dict, Any, Type
18
+
19
+ class ExceptionHandler:
20
+ def format_exception(exc_type: Type[Exception], exc_value: Exception, exc_traceback: Any) -> str:
21
+ """
22
+ :param exc_type: 异常类型
23
+ :param exc_value: 异常值
24
+ :param exc_traceback: 追踪信息
25
+ :return: 格式化后的异常信息
26
+ """
27
+ ...
28
+ def format_async_exception(exception: Exception) -> str:
29
+ """
30
+ :param exception: 异常对象
31
+ :return: 格式化后的异常信息
32
+ """
33
+ ...
34
+
35
+ def global_exception_handler(exc_type: Type[Exception], exc_value: Exception, exc_traceback: Any) -> None:
36
+ """
37
+ 全局异常处理器
38
+
39
+ :param exc_type: 异常类型
40
+ :param exc_value: 异常值
41
+ :param exc_traceback: 追踪信息
42
+ """
43
+ ...
44
+
45
+ def async_exception_handler(loop: asyncio.AbstractEventLoop, context: Dict[(str, Any)]) -> None:
46
+ """
47
+ 异步异常处理器
48
+
49
+ :param loop: 事件循环
50
+ :param context: 上下文字典
51
+ """
52
+ ...
53
+
54
+ def setup_async_loop(loop: asyncio.AbstractEventLoop = ...) -> None:
55
+ """
56
+ 为指定的事件循环设置异常处理器
57
+
58
+ :param loop: 事件循环实例,如果为None则使用当前事件循环
59
+ """
60
+ ...