maxkit 2.13.0__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.
aiomax/utils.py ADDED
@@ -0,0 +1,125 @@
1
+ from inspect import signature
2
+ from typing import Any, Callable, Literal
3
+
4
+ import aiohttp
5
+
6
+ from aiomax.types import Attachment
7
+
8
+ from . import buttons, exceptions
9
+
10
+
11
+ def get_message_body(
12
+ text: "str | None" = None,
13
+ format: "Literal['markdown', 'html'] | None" = None,
14
+ reply_to: "int | None" = None,
15
+ notify: bool = True,
16
+ keyboard: """list[list[buttons.Button]] \
17
+ | buttons.KeyboardBuilder \
18
+ | None""" = None,
19
+ attachments: "list[Attachment] | Attachment | None" = None,
20
+ ) -> dict:
21
+ """
22
+ Returns the body of the message as json.
23
+ """
24
+ body: dict[str, Any] = {"text": text, "format": format, "notify": notify}
25
+
26
+ # replying
27
+ if reply_to:
28
+ body["link"] = {"type": "reply", "mid": reply_to}
29
+
30
+ # keyboard
31
+ if keyboard:
32
+ if isinstance(keyboard, buttons.KeyboardBuilder):
33
+ keyboard = keyboard.to_list()
34
+
35
+ body["attachments"] = [
36
+ {
37
+ "type": "inline_keyboard",
38
+ "payload": {
39
+ "buttons": [
40
+ [
41
+ i.to_json() if isinstance(i, buttons.Button) else i
42
+ for i in row
43
+ ]
44
+ for row in keyboard
45
+ ]
46
+ },
47
+ }
48
+ ]
49
+
50
+ if attachments:
51
+ if "attachments" not in body:
52
+ body["attachments"] = []
53
+
54
+ if not isinstance(attachments, list):
55
+ attachments = [attachments]
56
+
57
+ for at in attachments or []:
58
+ if not hasattr(at, "as_dict"):
59
+ raise exceptions.AiomaxException(
60
+ "This attachment cannot be sent"
61
+ )
62
+ body["attachments"].append(at.as_dict())
63
+
64
+ if attachments == [] and "attachments" not in body:
65
+ body["attachments"] = []
66
+
67
+ return body
68
+
69
+
70
+ def context_kwargs(func: Callable, **kwargs):
71
+ """
72
+ Returns only those kwargs, that callable accepts
73
+ """
74
+ params = list(signature(func).parameters.keys())
75
+
76
+ kwargs = {kw: arg for kw, arg in kwargs.items() if kw in params}
77
+
78
+ return kwargs
79
+
80
+
81
+ async def get_exception(response: aiohttp.ClientResponse):
82
+ if response.status in range(200, 300):
83
+ return None
84
+
85
+ if response.content_type == "text/plain":
86
+ text = await response.text()
87
+ description = None
88
+
89
+ elif response.content_type == "application/json":
90
+ resp_json = await response.json()
91
+ # ``code`` may be absent in some error bodies; default to "" so the
92
+ # str checks below don't blow up with `None.startswith(...)`.
93
+ text = resp_json.get("code") or ""
94
+ description = resp_json.get("message")
95
+
96
+ else:
97
+ return Exception(f"Unknown error: {await response.read()}")
98
+
99
+ if text.startswith("Invalid access_token"):
100
+ return exceptions.InvalidToken()
101
+
102
+ if (
103
+ text == "attachment.not.ready"
104
+ or description == "Key: errors.process.attachment.video.not.processed"
105
+ ):
106
+ return exceptions.AttachmentNotReady()
107
+
108
+ if text == "chat.not.found":
109
+ return exceptions.ChatNotFound(description)
110
+
111
+ if description == "text: size must be between 0 and 4000":
112
+ return exceptions.IncorrectTextLength()
113
+
114
+ if text == "internal.error":
115
+ if description:
116
+ return exceptions.InternalError(description.split()[-1])
117
+ return exceptions.InternalError()
118
+
119
+ if text == "access.denied":
120
+ return exceptions.AccessDeniedException(description)
121
+
122
+ if text == "not.found":
123
+ return exceptions.NotFoundException(description)
124
+
125
+ return exceptions.UnknownErrorException(text, description)
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: maxkit
3
+ Version: 2.13.0
4
+ Summary: Asynchronous framework for Max Bot API (maintained successor of aiomax)
5
+ Author-email: mbutsk <mbutsk@icloud.com>, moontr3 <contact@moontr3.ru>
6
+ Maintainer-email: Aleksandr Kovalko <gistrec@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Docs, https://github.com/gistrec/maxkit/wiki
9
+ Project-URL: Source code, https://github.com/gistrec/maxkit
10
+ Keywords: bot,api,asyncio,max,aiomax
11
+ Classifier: Framework :: AsyncIO
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Communications :: Chat
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.md
23
+ Requires-Dist: aiohttp
24
+ Requires-Dist: aiofiles
25
+ Dynamic: license-file
26
+
27
+ # maxkit
28
+
29
+ Асинхронный фреймворк [Max](https://max.ru) Bot API.
30
+
31
+ Поддерживаемый преемник [aiomax](https://github.com/dpnspn/aiomax)
32
+ (оригинальный репозиторий заархивирован 14.07.2026). Модуль по-прежнему
33
+ импортируется как `aiomax` — переход сводится к замене зависимости.
34
+
35
+ ## Преимущества
36
+
37
+ - Полная асинхронность
38
+
39
+ - Возможность разделения на роутеры
40
+
41
+ - Эквиваленты всех функций доступных в Max Bot API
42
+
43
+ - Встроенный конечный автомат (FSM)
44
+
45
+ - Поддержка [PyPy](https://pypy.org/)
@@ -0,0 +1,16 @@
1
+ aiomax/__init__.py,sha256=HtxYmM41JQIjCadaww8r0A7xjii95Rk6DLpsanrrM4M,222
2
+ aiomax/bot.py,sha256=ffYnAMvXPqNEtYgYPaArn05dxL3PIYeaSFeFLEuR7B0,40099
3
+ aiomax/buttons.py,sha256=l3R-caI5-czNNALciNFwCI3k8ZKvLmAYz6JopSJEEIc,8271
4
+ aiomax/cache.py,sha256=8_LGaKxxjySj-0FNvcnH9Sy36-rvYJ5ryN0iUDKHq0E,802
5
+ aiomax/exceptions.py,sha256=VIv-LD22o-yML74wk_mO9Kz-G77SkFyeiVxleiDTjdU,1679
6
+ aiomax/filters.py,sha256=P8QKfrfgSEGEv75oq2rEeoChc0BqgaMWI4wTqferW7o,4547
7
+ aiomax/fsm.py,sha256=5bo3FCWsg6fOPuBqi1DAG-deg2uzp3CHCM78qjJPaQs,2683
8
+ aiomax/router.py,sha256=pLUfyais82J203GT2sJTI-yQ_Nv0vGd8-X7oVp-dLUU,10736
9
+ aiomax/russian_trusted_root_ca.cer,sha256=CBmXdQLZrtIjSDD2_7kfgvQB02dMblHdGeFtiz2_DrQ,2056
10
+ aiomax/types.py,sha256=7t2dDIaSU-rc5XbeNuPhCjtN2iWscH-uWbtGT2_hbsQ,47097
11
+ aiomax/utils.py,sha256=OuGgY-a-LEdLOAi_vhhXcTwIbshDgMJn-cEY2LTqClg,3646
12
+ maxkit-2.13.0.dist-info/licenses/LICENSE.md,sha256=pfBNYwt72grK5kTCDOkLvVmSeUF69GleBowMgzsENGQ,1106
13
+ maxkit-2.13.0.dist-info/METADATA,sha256=cBicCns74VeE655KVV0ipsjTK61aVV-jjx6uIWC5eWo,1818
14
+ maxkit-2.13.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
15
+ maxkit-2.13.0.dist-info/top_level.txt,sha256=7YZN0tu2cv5hbUyTdZQC5lGAx4lx49MTBUOj6KktlQQ,7
16
+ maxkit-2.13.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 OAA DPNSPN
4
+ Copyright (c) 2026 Aleksandr Kovalko
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ aiomax