aiogram_tool 1.0.0__tar.gz → 1.0.1__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.
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/PKG-INFO +4 -3
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/components/filter.py +9 -6
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/components/middleware.py +10 -7
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/depend.py +16 -15
- aiogram_tool-1.0.1/aiogram_tool/depend/utils/inject.py +56 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/setup.py +2 -2
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/pyproject.toml +14 -4
- aiogram_tool-1.0.0/aiogram_tool/depend/utils/inject.py +0 -33
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/LICENSE.md +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/README.md +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/components/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/setup.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/depend/utils/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/limit.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/storage/__init__.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/storage/abstract_storage.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/storage/memory_storage.py +0 -0
- {aiogram_tool-1.0.0 → aiogram_tool-1.0.1}/aiogram_tool/limit/storage/redis_storage.py +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: aiogram_tool
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: Tools which doing work with aiogram simple
|
|
5
|
-
License:
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: aiogram,rate,throttling,limit,dependency-injection,depends,cooldown,delay
|
|
6
7
|
Author: Vlad_shayzi1
|
|
7
8
|
Author-email: tecnomega@mail.ru
|
|
8
9
|
Requires-Python: >=3.10
|
|
9
|
-
Classifier: License ::
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Programming Language :: Python :: 3
|
|
11
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from typing import Any
|
|
2
|
+
from contextlib import AsyncExitStack
|
|
2
3
|
|
|
3
4
|
from aiogram.filters import Filter
|
|
4
5
|
from aiogram import Dispatcher
|
|
@@ -20,9 +21,11 @@ class DependFilter(Filter):
|
|
|
20
21
|
dependency_override: dict[str, Depend] = dispatcher.workflow_data.get("dependency_override", {})
|
|
21
22
|
|
|
22
23
|
kwargs.update({"event": args[0]})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
async with AsyncExitStack() as stack:
|
|
25
|
+
depend_kwargs = await inject_parametrs(
|
|
26
|
+
callback=handler_object.callback,
|
|
27
|
+
dependency_override=dependency_override,
|
|
28
|
+
middleware_data=kwargs,
|
|
29
|
+
stack=stack
|
|
30
|
+
)
|
|
31
|
+
return depend_kwargs
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from typing import Any, Callable, Awaitable
|
|
2
|
+
from contextlib import AsyncExitStack
|
|
2
3
|
|
|
3
4
|
from aiogram.dispatcher.middlewares.base import BaseMiddleware
|
|
4
5
|
from aiogram.types.base import TelegramObject
|
|
@@ -27,10 +28,12 @@ class DependMiddleware(BaseMiddleware):
|
|
|
27
28
|
dependency_override: dict[str, Depend] = dispatcher.workflow_data.get("dependency_override", {})
|
|
28
29
|
|
|
29
30
|
data.update({"event": event})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
async with AsyncExitStack() as stack:
|
|
32
|
+
inject = await inject_parametrs(
|
|
33
|
+
callback=handler_object.callback,
|
|
34
|
+
dependency_override=dependency_override,
|
|
35
|
+
middleware_data=data,
|
|
36
|
+
stack=stack
|
|
37
|
+
)
|
|
38
|
+
data.update(inject)
|
|
39
|
+
return await handler(event, data)
|
|
@@ -2,7 +2,8 @@ import inspect
|
|
|
2
2
|
|
|
3
3
|
from contextlib import (
|
|
4
4
|
asynccontextmanager,
|
|
5
|
-
contextmanager
|
|
5
|
+
contextmanager,
|
|
6
|
+
AsyncExitStack
|
|
6
7
|
)
|
|
7
8
|
from typing import (
|
|
8
9
|
Callable,
|
|
@@ -56,7 +57,7 @@ class Depend:
|
|
|
56
57
|
|
|
57
58
|
for type_ in types:
|
|
58
59
|
name = getattr(type_, "__name__", None)
|
|
59
|
-
if name
|
|
60
|
+
if name in "_AsyncGeneratorContextManager":
|
|
60
61
|
self.isasync = True
|
|
61
62
|
self.isgenerator = True
|
|
62
63
|
|
|
@@ -71,33 +72,33 @@ class Depend:
|
|
|
71
72
|
|
|
72
73
|
if isinstance(annotation.annotation, _AnnotatedAlias):
|
|
73
74
|
types = getattr(annotation.annotation, "__metadata__")
|
|
74
|
-
for
|
|
75
|
-
if isinstance(
|
|
76
|
-
self.arguments[key] =
|
|
75
|
+
for dep in types:
|
|
76
|
+
if isinstance(dep, Depend):
|
|
77
|
+
self.arguments[key] = dep
|
|
77
78
|
|
|
78
79
|
elif isinstance(default_value, Depend):
|
|
79
80
|
self.arguments[key] = default_value
|
|
80
81
|
|
|
81
82
|
else:
|
|
82
83
|
self.arguments[key] = annotation.annotation
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
|
|
85
|
+
async def call(
|
|
86
|
+
self,
|
|
87
|
+
middleware_data: dict[str, Any],
|
|
88
|
+
stack: AsyncExitStack
|
|
89
|
+
) -> Any:
|
|
86
90
|
kwargs = {}
|
|
87
91
|
for key, value in self.arguments.items():
|
|
88
92
|
if isinstance(value, Depend):
|
|
89
|
-
kwargs[key] = await value.call(middleware_data)
|
|
93
|
+
kwargs[key] = await value.call(middleware_data, stack)
|
|
90
94
|
else:
|
|
91
95
|
kwargs[key] = middleware_data.get(key)
|
|
92
|
-
|
|
96
|
+
|
|
93
97
|
if self.isasync is False:
|
|
94
98
|
if self.isgenerator is True:
|
|
95
|
-
|
|
96
|
-
return value
|
|
99
|
+
return stack.enter_context(self.obj(**kwargs))
|
|
97
100
|
return self.obj(**kwargs)
|
|
98
|
-
|
|
99
101
|
else:
|
|
100
102
|
if self.isgenerator is True:
|
|
101
|
-
|
|
102
|
-
return asvalue
|
|
103
|
+
return await stack.enter_async_context(self.obj(**kwargs))
|
|
103
104
|
return await self.obj(**kwargs)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
from contextlib import AsyncExitStack
|
|
4
|
+
from typing import (
|
|
5
|
+
Any,
|
|
6
|
+
Callable,
|
|
7
|
+
_AnnotatedAlias
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
from ..depend import Depend
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def depend_call(
|
|
15
|
+
depend: Depend,
|
|
16
|
+
dependency_override: dict[str, Any],
|
|
17
|
+
middleware_data: dict[str, Any],
|
|
18
|
+
stack: AsyncExitStack
|
|
19
|
+
) -> Any:
|
|
20
|
+
call_object = depend
|
|
21
|
+
if depend.obj_name in dependency_override.keys():
|
|
22
|
+
call_object = dependency_override.get(depend.obj_name)
|
|
23
|
+
return await call_object.call(middleware_data, stack)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
async def inject_parametrs(
|
|
28
|
+
callback: Callable,
|
|
29
|
+
stack: AsyncExitStack,
|
|
30
|
+
middleware_data: dict[str, Any],
|
|
31
|
+
dependency_override: dict[str, Depend] = {},
|
|
32
|
+
) -> dict[str, Any]:
|
|
33
|
+
data = {}
|
|
34
|
+
signature = inspect.signature(callback)
|
|
35
|
+
for key, annotation in signature.parameters.items():
|
|
36
|
+
default_value = annotation.default
|
|
37
|
+
|
|
38
|
+
if isinstance(annotation.annotation, _AnnotatedAlias):
|
|
39
|
+
types = getattr(annotation.annotation, "__metadata__")
|
|
40
|
+
for dep in types:
|
|
41
|
+
if isinstance(dep, Depend):
|
|
42
|
+
data[key] = await depend_call(
|
|
43
|
+
depend=dep,
|
|
44
|
+
dependency_override=dependency_override,
|
|
45
|
+
middleware_data=middleware_data,
|
|
46
|
+
stack=stack
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
elif isinstance(default_value, Depend):
|
|
50
|
+
data[key] = await depend_call(
|
|
51
|
+
depend=default_value,
|
|
52
|
+
dependency_override=dependency_override,
|
|
53
|
+
middleware_data=middleware_data,
|
|
54
|
+
stack=stack
|
|
55
|
+
)
|
|
56
|
+
return data
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
|
|
3
3
|
from typing import Callable, Awaitable
|
|
4
|
-
from aiogram.types import
|
|
4
|
+
from aiogram.types.base import TelegramObject
|
|
5
5
|
from aiogram import Dispatcher
|
|
6
6
|
|
|
7
7
|
from datetime import datetime, timedelta
|
|
@@ -14,7 +14,7 @@ from .storage import MemoryStorage
|
|
|
14
14
|
def setup_limit_tool(
|
|
15
15
|
dispatcher: Dispatcher,
|
|
16
16
|
storage: AbstractStorage = MemoryStorage(),
|
|
17
|
-
answer_callback: Callable[[
|
|
17
|
+
answer_callback: Callable[[TelegramObject, timedelta, datetime], Awaitable] | None = None
|
|
18
18
|
) -> None:
|
|
19
19
|
if not issubclass(type(storage), AbstractStorage):
|
|
20
20
|
raise TypeError(f"Invalid type for storage")
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "aiogram_tool"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.1"
|
|
4
4
|
description = "Tools which doing work with aiogram simple"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Vlad_shayzi1",email = "tecnomega@mail.ru"}
|
|
7
7
|
]
|
|
8
|
-
license = "
|
|
8
|
+
license = "MIT"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"redis (>=6.2.0,<7.0.0)",
|
|
13
|
+
"aiogram (>=3.21.0,<4.0.0)"
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"aiogram",
|
|
17
|
+
"rate",
|
|
18
|
+
"throttling",
|
|
19
|
+
"limit",
|
|
20
|
+
"dependency-injection",
|
|
21
|
+
"depends",
|
|
22
|
+
"cooldown",
|
|
23
|
+
"delay"
|
|
14
24
|
]
|
|
15
25
|
|
|
16
26
|
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import inspect
|
|
2
|
-
|
|
3
|
-
from typing import Any, Callable, _AnnotatedAlias
|
|
4
|
-
|
|
5
|
-
from ..depend import Depend
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
async def inject_parametrs(
|
|
10
|
-
callback: Callable,
|
|
11
|
-
middleware_data: dict[str, Any],
|
|
12
|
-
dependency_override: dict[str, Depend] = {},
|
|
13
|
-
) -> dict[str, Any]:
|
|
14
|
-
data = {}
|
|
15
|
-
signature = inspect.signature(callback)
|
|
16
|
-
for key, annotation in signature.parameters.items():
|
|
17
|
-
default_value = annotation.default
|
|
18
|
-
|
|
19
|
-
if isinstance(annotation.annotation, _AnnotatedAlias):
|
|
20
|
-
types = getattr(annotation.annotation, "__metadata__")
|
|
21
|
-
for type_ in types:
|
|
22
|
-
if isinstance(type_, Depend):
|
|
23
|
-
if type_.obj_name in dependency_override.keys():
|
|
24
|
-
data[key] = await dependency_override[type_.obj_name].call(middleware_data)
|
|
25
|
-
else:
|
|
26
|
-
data[key] = await type_.call(middleware_data)
|
|
27
|
-
|
|
28
|
-
elif isinstance(default_value, Depend):
|
|
29
|
-
if default_value.obj_name in dependency_override.keys():
|
|
30
|
-
data[key] = await dependency_override[default_value.obj_name].call(middleware_data)
|
|
31
|
-
else:
|
|
32
|
-
data[key] = await default_value.call(middleware_data)
|
|
33
|
-
return data
|
|
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
|