satori-python 0.16.5__tar.gz → 0.16.7__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.
- {satori_python-0.16.5 → satori_python-0.16.7}/PKG-INFO +1 -1
- {satori_python-0.16.5 → satori_python-0.16.7}/pyproject.toml +1 -1
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/__init__.py +1 -1
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/__init__.py +16 -14
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/__init__.py +2 -1
- {satori_python-0.16.5 → satori_python-0.16.7}/LICENSE +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/README.md +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/account.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/account.pyi +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/config.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/network/__init__.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/network/base.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/network/util.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/network/webhook.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/network/websocket.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/client/protocol.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/const.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/element.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/event.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/exception.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/model.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/parser.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/adapter.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/connection.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/formdata.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/model.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/route.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/server/utils.py +0 -0
- {satori_python-0.16.5 → satori_python-0.16.7}/src/satori/utils.py +0 -0
|
@@ -38,10 +38,20 @@ MAPPING: dict[type[Config], type[BaseNetwork]] = {
|
|
|
38
38
|
_app: App | None = None
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
@overload
|
|
42
|
+
def get_accounts() -> dict[str, Account]: ...
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@overload
|
|
46
|
+
def get_accounts(self_id: str) -> list[Account]: ...
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_accounts(self_id: str | None = None):
|
|
42
50
|
if _app is None:
|
|
43
51
|
raise RuntimeError("App instance is not initialized.")
|
|
44
|
-
|
|
52
|
+
if not self_id:
|
|
53
|
+
return _app.accounts
|
|
54
|
+
return [acc for acc in _app.accounts.values() if acc.self_info.user.id == self_id]
|
|
45
55
|
|
|
46
56
|
|
|
47
57
|
def get_app() -> App:
|
|
@@ -51,13 +61,6 @@ def get_app() -> App:
|
|
|
51
61
|
return _app
|
|
52
62
|
|
|
53
63
|
|
|
54
|
-
def get_account(self_id: str) -> Account:
|
|
55
|
-
"""Get an account by its self_id."""
|
|
56
|
-
if _app is None:
|
|
57
|
-
raise RuntimeError("App instance is not initialized.")
|
|
58
|
-
return _app.get_account(self_id)
|
|
59
|
-
|
|
60
|
-
|
|
61
64
|
class App(Service):
|
|
62
65
|
id = "satori-python.client"
|
|
63
66
|
required: set[str] = {"http.client/aiohttp"}
|
|
@@ -72,10 +75,12 @@ class App(Service):
|
|
|
72
75
|
def register_config(cls, tc: type[TConfig], tn: type[BaseNetwork[TConfig]]):
|
|
73
76
|
MAPPING[tc] = tn
|
|
74
77
|
|
|
75
|
-
def __init__(
|
|
78
|
+
def __init__(
|
|
79
|
+
self, *configs: Config, default_api_cls: type[ApiProtocol] = ApiProtocol, main_app: bool = True
|
|
80
|
+
):
|
|
76
81
|
global _app
|
|
77
82
|
|
|
78
|
-
if _app is not None:
|
|
83
|
+
if _app is not None and main_app:
|
|
79
84
|
raise RuntimeError("App instance already exists. Only one App instance is allowed.")
|
|
80
85
|
self.accounts = {}
|
|
81
86
|
self.connections = []
|
|
@@ -94,9 +99,6 @@ class App(Service):
|
|
|
94
99
|
raise TypeError(f"Unknown config type: {config}")
|
|
95
100
|
self.connections.append(connection)
|
|
96
101
|
|
|
97
|
-
def get_account(self, self_id: str) -> Account:
|
|
98
|
-
return self.accounts[self_id]
|
|
99
|
-
|
|
100
102
|
def register(self, callback: Callable[[Account, Event], Awaitable[Any]]):
|
|
101
103
|
self.event_callbacks.append(callback)
|
|
102
104
|
|
|
@@ -33,6 +33,7 @@ from starlette.responses import Response as Response
|
|
|
33
33
|
from starlette.responses import StreamingResponse as StreamingResponse
|
|
34
34
|
from starlette.routing import Route, WebSocketRoute
|
|
35
35
|
from starlette.staticfiles import StaticFiles
|
|
36
|
+
from starlette.types import ASGIApp
|
|
36
37
|
from starlette.websockets import WebSocket, WebSocketDisconnect
|
|
37
38
|
from yarl import URL
|
|
38
39
|
|
|
@@ -139,7 +140,7 @@ class Server(Service, RouterMixin):
|
|
|
139
140
|
self.app = Starlette()
|
|
140
141
|
super().__init__()
|
|
141
142
|
|
|
142
|
-
def replace_app(self, app: asgitypes.ASGI3Application):
|
|
143
|
+
def replace_app(self, app: ASGIApp | asgitypes.ASGI3Application):
|
|
143
144
|
"""替换当前的 Starlette 应用"""
|
|
144
145
|
self.app = app
|
|
145
146
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|