satori-python 0.13.2__tar.gz → 0.13.3__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 (27) hide show
  1. {satori_python-0.13.2 → satori_python-0.13.3}/PKG-INFO +1 -1
  2. {satori_python-0.13.2 → satori_python-0.13.3}/pyproject.toml +1 -1
  3. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/__init__.py +1 -1
  4. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/account.py +9 -6
  5. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/account.pyi +10 -7
  6. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/network/webhook.py +1 -1
  7. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/network/websocket.py +1 -0
  8. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/parser.py +5 -2
  9. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/server/__init__.py +2 -1
  10. {satori_python-0.13.2 → satori_python-0.13.3}/LICENSE +0 -0
  11. {satori_python-0.13.2 → satori_python-0.13.3}/README.md +0 -0
  12. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/__init__.py +0 -0
  13. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/network/__init__.py +0 -0
  14. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/network/base.py +0 -0
  15. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/network/util.py +0 -0
  16. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/client/protocol.py +0 -0
  17. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/config.py +0 -0
  18. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/const.py +0 -0
  19. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/element.py +0 -0
  20. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/event.py +0 -0
  21. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/exception.py +0 -0
  22. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/model.py +0 -0
  23. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/server/adapter.py +0 -0
  24. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/server/conection.py +0 -0
  25. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/server/formdata.py +0 -0
  26. {satori_python-0.13.2 → satori_python-0.13.3}/src/satori/server/model.py +0 -0
  27. {satori_python-0.13.2 → satori_python-0.13.3}/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.13.2
3
+ Version: 0.13.3
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>
@@ -29,7 +29,7 @@ classifiers = [
29
29
  "Programming Language :: Python :: 3.12",
30
30
  "Operating System :: OS Independent",
31
31
  ]
32
- version = "0.13.2"
32
+ version = "0.13.3"
33
33
 
34
34
  [project.license]
35
35
  text = "MIT"
@@ -43,4 +43,4 @@ from .model import Role as Role
43
43
  from .model import Upload as Upload
44
44
  from .model import User as User
45
45
 
46
- __version__ = "0.13.2"
46
+ __version__ = "0.13.3"
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  from dataclasses import dataclass
5
- from typing import TypeVar
5
+ from typing import Generic, TypeVar
6
6
 
7
7
  from yarl import URL
8
8
 
@@ -11,6 +11,7 @@ from satori.model import Login
11
11
  from .protocol import ApiProtocol
12
12
 
13
13
  TP = TypeVar("TP", bound="ApiProtocol")
14
+ TP1 = TypeVar("TP1", bound="ApiProtocol")
14
15
 
15
16
 
16
17
  @dataclass
@@ -29,14 +30,14 @@ class ApiInfo:
29
30
  return URL(f"http://{self.host}:{self.port}{self.path}") / "v1"
30
31
 
31
32
 
32
- class Account:
33
+ class Account(Generic[TP]):
33
34
  def __init__(
34
35
  self,
35
36
  platform: str,
36
37
  self_id: str,
37
38
  self_info: Login,
38
39
  config: ApiInfo,
39
- protocol_cls: type[ApiProtocol] = ApiProtocol,
40
+ protocol_cls: type[TP] = ApiProtocol,
40
41
  ):
41
42
  self.platform = platform
42
43
  self.self_id = self_id
@@ -45,14 +46,16 @@ class Account:
45
46
  self.protocol = protocol_cls(self) # type: ignore
46
47
  self.connected = asyncio.Event()
47
48
 
48
- def custom(self, config: ApiInfo | None = None, protocol_cls: type[TP] = ApiProtocol, **kwargs) -> TP:
49
+ def custom(
50
+ self, config: ApiInfo | None = None, protocol_cls: type[TP1] = ApiProtocol, **kwargs
51
+ ) -> "Account[TP1]":
49
52
  return Account(
50
53
  self.platform,
51
54
  self.self_id,
52
55
  self.self_info,
53
- config or ApiInfo(**kwargs),
56
+ config or (ApiInfo(**kwargs) if kwargs else self.config),
54
57
  protocol_cls, # type: ignore
55
- ).protocol
58
+ )
56
59
 
57
60
  @property
58
61
  def identity(self):
@@ -1,5 +1,5 @@
1
1
  import asyncio
2
- from typing import Any, Iterable, Protocol, TypeVar, overload
2
+ from typing import Any, Generic, Iterable, Protocol, TypeVar, overload
3
3
 
4
4
  from yarl import URL
5
5
 
@@ -23,6 +23,7 @@ from satori.model import (
23
23
  from .protocol import ApiProtocol
24
24
 
25
25
  TP = TypeVar("TP", bound="ApiProtocol")
26
+ TP1 = TypeVar("TP1", bound="ApiProtocol")
26
27
 
27
28
  class Api(Protocol):
28
29
  token: str | None = None
@@ -35,12 +36,12 @@ class ApiInfo(Api):
35
36
  self, host: str = "localhost", port: int = 5140, path: str = "", token: str | None = None
36
37
  ): ...
37
38
 
38
- class Account:
39
+ class Account(Generic[TP]):
39
40
  platform: str
40
41
  self_id: str
41
42
  self_info: Login
42
43
  config: Api
43
- protocol: ApiProtocol
44
+ protocol: TP
44
45
  connected: asyncio.Event
45
46
 
46
47
  def __init__(
@@ -49,16 +50,18 @@ class Account:
49
50
  self_id: str,
50
51
  self_info: Login,
51
52
  config: Api,
52
- protocol_cls: type[ApiProtocol] = ApiProtocol,
53
+ protocol_cls: type[TP] = ApiProtocol,
53
54
  ): ...
54
55
  @property
55
56
  def identity(self) -> str: ...
56
57
  @overload
57
- def custom(self, config: Api, protocol_cls: type[TP] = ApiProtocol) -> TP: ...
58
+ def custom(self, config: Api, protocol_cls: type[TP1] = ApiProtocol) -> Account[TP1]: ...
59
+ @overload
60
+ def custom(self, *, protocol_cls: type[TP1]) -> Account[TP1]: ...
58
61
  @overload
59
62
  def custom(
60
- self, *, protocol_cls: type[TP] = ApiProtocol, host: str, port: int, token: str | None = None
61
- ) -> TP: ...
63
+ self, *, protocol_cls: type[TP1] = ApiProtocol, host: str, port: int, token: str | None = None
64
+ ) -> Account[TP1]: ...
62
65
  async def send(self, event: Event, message: str | Iterable[str | Element]) -> list[MessageObject]:
63
66
  """发送消息。返回一个 `MessageObject` 对象构成的数组。
64
67
 
@@ -61,7 +61,7 @@ class WebhookNetwork(BaseNetwork[WebhookInfo]):
61
61
  op = data["op"]
62
62
  if op != Opcode.EVENT:
63
63
  return web.Response(status=202)
64
- logger.debug(f"Received payload: {data}")
64
+ logger.trace(f"Received payload: {data}")
65
65
  self.post_event(data["body"])
66
66
  return web.Response()
67
67
 
@@ -37,6 +37,7 @@ class WsNetwork(BaseNetwork[WebsocketsInfo]):
37
37
  return
38
38
  elif msg.type == aiohttp.WSMsgType.TEXT:
39
39
  data: dict = json.loads(cast(str, msg.data))
40
+ logger.trace(f"Received payload: {data}")
40
41
  if data["op"] == Opcode.EVENT:
41
42
  self.post_event(data["body"])
42
43
  elif data["op"] > 4:
@@ -97,8 +97,11 @@ class Element:
97
97
  self.attrs["is"] = type
98
98
  else:
99
99
  self.type = type
100
- if self.tag() == "text" and "content" in self.attrs:
101
- self.attrs["text"] = self.attrs.pop("content")
100
+ if self.tag() == "text":
101
+ if "content" in self.attrs:
102
+ self.attrs["text"] = self.attrs.pop("content")
103
+ elif not self.attrs:
104
+ self.attrs["text"] = ""
102
105
 
103
106
  def tag(self):
104
107
  if self.type == "component":
@@ -75,6 +75,7 @@ class Server(Service, RouterMixin):
75
75
  routers: list[Router]
76
76
  _adapters: list[Adapter]
77
77
  connections: list[WebsocketConnection]
78
+ session: aiohttp.ClientSession
78
79
 
79
80
  def __init__(
80
81
  self,
@@ -96,7 +97,6 @@ class Server(Service, RouterMixin):
96
97
  self.routers = []
97
98
  self.routes = {}
98
99
  self.webhooks = webhooks or []
99
- self.session = aiohttp.ClientSession()
100
100
  self._tempdir = TemporaryDirectory()
101
101
  self.proxy_url_mapping = {}
102
102
  super().__init__()
@@ -253,6 +253,7 @@ class Server(Service, RouterMixin):
253
253
  return res
254
254
 
255
255
  async def launch(self, manager: Launart):
256
+ self.session = aiohttp.ClientSession()
256
257
  for _adapter in self._adapters:
257
258
  manager.add_component(_adapter)
258
259
 
File without changes
File without changes