satori-python 0.11.0__tar.gz → 0.11.2__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.
Files changed (25) hide show
  1. {satori_python-0.11.0 → satori_python-0.11.2}/PKG-INFO +1 -1
  2. {satori_python-0.11.0 → satori_python-0.11.2}/pyproject.toml +1 -1
  3. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/__init__.py +1 -1
  4. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/__init__.py +23 -2
  5. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/element.py +5 -5
  6. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/server/__init__.py +24 -3
  7. {satori_python-0.11.0 → satori_python-0.11.2}/LICENSE +0 -0
  8. {satori_python-0.11.0 → satori_python-0.11.2}/README.md +0 -0
  9. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/account.py +0 -0
  10. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/account.pyi +0 -0
  11. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/network/__init__.py +0 -0
  12. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/network/base.py +0 -0
  13. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/network/webhook.py +0 -0
  14. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/network/websocket.py +0 -0
  15. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/client/session.py +0 -0
  16. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/config.py +0 -0
  17. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/const.py +0 -0
  18. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/event.py +0 -0
  19. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/exception.py +0 -0
  20. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/model.py +0 -0
  21. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/parser.py +0 -0
  22. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/server/adapter.py +0 -0
  23. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/server/conection.py +0 -0
  24. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/server/model.py +0 -0
  25. {satori_python-0.11.0 → satori_python-0.11.2}/src/satori/server/route.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: satori-python
3
- Version: 0.11.0
3
+ Version: 0.11.2
4
4
  Summary: Satori Protocol SDK for python
5
5
  Home-page: https://github.com/RF-Tar-Railt/satori-python
6
6
  Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
@@ -28,7 +28,7 @@ classifiers = [
28
28
  "Programming Language :: Python :: 3.12",
29
29
  "Operating System :: OS Independent",
30
30
  ]
31
- version = "0.11.0"
31
+ version = "0.11.2"
32
32
 
33
33
  [project.license]
34
34
  text = "MIT"
@@ -39,4 +39,4 @@ from .model import MessageObject as MessageObject
39
39
  from .model import Role as Role
40
40
  from .model import User as User
41
41
 
42
- __version__ = "0.11.0"
42
+ __version__ = "0.11.2"
@@ -1,7 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import functools
4
5
  import signal
6
+ import threading
5
7
  from functools import wraps
6
8
  from typing import Any, Awaitable, Callable, Iterable, Literal, TypeVar, overload
7
9
 
@@ -211,8 +213,27 @@ class App(Service):
211
213
  manager.add_component(self)
212
214
  manager.launch_blocking(loop=loop, stop_signal=stop_signal)
213
215
 
214
- async def run_async(self, manager: Launart | None = None):
216
+ async def run_async(
217
+ self,
218
+ manager: Launart | None = None,
219
+ stop_signal: Iterable[signal.Signals] = (signal.SIGINT,),
220
+ ):
215
221
  if manager is None:
216
222
  manager = it(Launart)
217
223
  manager.add_component(self)
218
- await manager.launch()
224
+ handled_signals: dict[signal.Signals, Any] = {}
225
+ launch_task = asyncio.create_task(manager.launch(), name="amnesia-launch")
226
+ signal_handler = functools.partial(manager._on_sys_signal, main_task=launch_task)
227
+ if threading.current_thread() is threading.main_thread(): # pragma: worst case
228
+ try:
229
+ for sig in stop_signal:
230
+ handled_signals[sig] = signal.getsignal(sig)
231
+ signal.signal(sig, signal_handler)
232
+ except ValueError: # pragma: no cover
233
+ # `signal.signal` may throw if `threading.main_thread` does
234
+ # not support signals
235
+ handled_signals.clear()
236
+ await launch_task
237
+ for sig, handler in handled_signals.items():
238
+ if signal.getsignal(sig) is signal_handler:
239
+ signal.signal(sig, handler)
@@ -2,7 +2,7 @@ from base64 import b64encode
2
2
  from dataclasses import InitVar, dataclass, field, fields
3
3
  from io import BytesIO
4
4
  from pathlib import Path
5
- from typing import Any, Dict, List, Optional, TypeVar, Union
5
+ from typing import Any, Dict, List, Optional, TypeVar, Union, get_args
6
6
  from typing_extensions import override
7
7
 
8
8
  from .parser import Element as RawElement
@@ -24,13 +24,14 @@ class Element:
24
24
  for f in fields(self):
25
25
  if f.name in ("_attrs", "_children"):
26
26
  continue
27
- if f.type is not str and isinstance(attr := getattr(self, f.name), str):
28
- if f.type is bool:
27
+ _type = get_args(f.type)[0] if hasattr(f.type, "__origin__") else f.type
28
+ if _type is not str and isinstance(attr := getattr(self, f.name), str):
29
+ if _type is bool:
29
30
  if attr.lower() not in ("true", "false"):
30
31
  raise TypeError(f.name, attr)
31
32
  setattr(self, f.name, attr.lower() == "true")
32
33
  else:
33
- setattr(self, f.name, f.type(attr))
34
+ setattr(self, f.name, _type(attr))
34
35
  self._attrs[f.name] = getattr(self, f.name)
35
36
  self._attrs = {k: v for k, v in self._attrs.items() if v is not None}
36
37
 
@@ -332,7 +333,6 @@ class Message(Element):
332
333
  self.__call__(*content or [])
333
334
 
334
335
 
335
- @dataclass
336
336
  class Quote(Message):
337
337
  """<quote> 元素用于表示对消息引用。
338
338
 
@@ -1,10 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import functools
4
5
  import signal
6
+ import threading
5
7
  from contextlib import suppress
6
8
  from traceback import print_exc
7
- from typing import Callable, Iterable, Literal, cast, overload
9
+ from typing import Any, Callable, Iterable, Literal, cast, overload
8
10
 
9
11
  import aiohttp
10
12
  from creart import it
@@ -383,8 +385,27 @@ class Server(Service):
383
385
  manager.add_component(self)
384
386
  manager.launch_blocking(loop=loop, stop_signal=stop_signal)
385
387
 
386
- async def run_async(self, manager: Launart | None = None):
388
+ async def run_async(
389
+ self,
390
+ manager: Launart | None = None,
391
+ stop_signal: Iterable[signal.Signals] = (signal.SIGINT,),
392
+ ):
387
393
  if manager is None:
388
394
  manager = it(Launart)
389
395
  manager.add_component(self)
390
- await manager.launch()
396
+ handled_signals: dict[signal.Signals, Any] = {}
397
+ launch_task = asyncio.create_task(manager.launch(), name="amnesia-launch")
398
+ signal_handler = functools.partial(manager._on_sys_signal, main_task=launch_task)
399
+ if threading.current_thread() is threading.main_thread(): # pragma: worst case
400
+ try:
401
+ for sig in stop_signal:
402
+ handled_signals[sig] = signal.getsignal(sig)
403
+ signal.signal(sig, signal_handler)
404
+ except ValueError: # pragma: no cover
405
+ # `signal.signal` may throw if `threading.main_thread` does
406
+ # not support signals
407
+ handled_signals.clear()
408
+ await launch_task
409
+ for sig, handler in handled_signals.items():
410
+ if signal.getsignal(sig) is signal_handler:
411
+ signal.signal(sig, handler)
File without changes
File without changes