aiogram_tool 1.2.3__tar.gz → 1.2.4__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.2.3 → aiogram_tool-1.2.4}/PKG-INFO +1 -1
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/callback_data/filter.py +7 -2
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/stack_manager.py +1 -1
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/pyproject.toml +1 -1
- aiogram_tool-1.2.4/tests/callback_data/test_unique_id.py +40 -0
- aiogram_tool-1.2.4/tests/depend/test_stack_exception.py +44 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/uv.lock +1 -1
- aiogram_tool-1.2.3/tests/callback_data/test_unique_id.py +0 -13
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/.github/workflows/main.yml +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/.github/workflows/release.yml +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/.gitignore +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/.pre-commit-config.yaml +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/.python-version +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/CONTRIBUTING.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/LICENSE.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/README.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/base.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/impl/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/impl/file.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/impl/memory.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/storage/impl/redis.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/callback_data/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/callback_data/answer.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/exit.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/filter.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/inner_middleware.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/outer_middleware.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/depend.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/storage/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/storage/memory.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/tool.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/types/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/types/enums.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/types/exceptions.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/types/schema.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/inspect.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/registry_manager.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/resolver.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/scope_registry.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/answer.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/filter.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/base.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/fixed_window.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/sliding_window.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/token_bucket.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/schema.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/tool.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/setup.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/types.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/en/callback_data.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/en/depend.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/en/limit.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/en/setup.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/en/storages.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/ru/callback_data.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/ru/depend.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/ru/limit.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/ru/setup.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/docs/ru/storages.md +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/callback_data/basic.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/callback_data/custom_expired_answer.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/callback_data/redis_storage.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/depend/classes.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/depend/filter_and_exit.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/depend/override.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/depend/scopes.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/depend/subdepends.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/limit/advanced.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/limit/basic.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/examples/limit/limit_algorithms.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/pytest.ini +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/callback_data/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/callback_data/conftest.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/callback_data/test_filter.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/callback_data/test_pack.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/callback_data/test_with_handler.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/conftest.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/conftest.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_classes.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_exit.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_filter.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_from.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_generator.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_lambda.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_middleware_data.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_override.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_scopes.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_setup.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_singleton_lock.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/depend/test_subdepend.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/limit/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/limit/conftest.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/limit/test_rate_limits.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/limit/test_setup.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/storage/__init__.py +0 -0
- {aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/tests/storage/test_storages.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: aiogram-tool
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
4
|
Summary: Tools which doing work with aiogram simple
|
|
5
5
|
Project-URL: Repository, https://github.com/shayzi3/aiogram_tool
|
|
6
6
|
Project-URL: Contributing, https://github.com/shayzi3/aiogram_tool/blob/master/CONTRIBUTING.md
|
|
@@ -20,9 +20,14 @@ class _UniqueIDCallbackData(CallbackData, prefix=UNIQUE_PREFIX):
|
|
|
20
20
|
|
|
21
21
|
@classmethod
|
|
22
22
|
def build(cls, callback_data: type[CallbackData]) -> Self:
|
|
23
|
-
separators_len = len(cls.__separator__) * len(cls.model_fields)
|
|
23
|
+
separators_len = len(cls.__separator__.encode("utf-8")) * len(cls.model_fields)
|
|
24
24
|
unique_id_len = (
|
|
25
|
-
64
|
|
25
|
+
64
|
|
26
|
+
- (
|
|
27
|
+
len(UNIQUE_PREFIX.encode("utf-8"))
|
|
28
|
+
+ len(callback_data.__prefix__.encode("utf-8"))
|
|
29
|
+
+ separators_len
|
|
30
|
+
)
|
|
26
31
|
) // 2
|
|
27
32
|
|
|
28
33
|
if unique_id_len < 6:
|
|
@@ -13,7 +13,7 @@ class AsyncExitStackTransaction:
|
|
|
13
13
|
return self
|
|
14
14
|
|
|
15
15
|
async def __aexit__(self, *args) -> None:
|
|
16
|
-
await self.stack.
|
|
16
|
+
await self.stack.__aexit__(*args)
|
|
17
17
|
|
|
18
18
|
def _get_stack(self, scope: Scope) -> AsyncExitStack:
|
|
19
19
|
return self.app_stack if scope == Scope.SINGLETON else self.stack
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from aiogram_tool.storage.impl.memory import MemoryStorage
|
|
4
|
+
from aiogram_tool.tools.callback_data.filter import (
|
|
5
|
+
LongCallbackData,
|
|
6
|
+
LongCallbackQueryFilter,
|
|
7
|
+
_UniqueIDCallbackData,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
from .conftest import CallbackQueryFactoryType
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def test_unique_id_data_error() -> None:
|
|
14
|
+
|
|
15
|
+
class Data(LongCallbackData, prefix="LONG" * 13):
|
|
16
|
+
attr: str
|
|
17
|
+
|
|
18
|
+
with pytest.raises(ValueError):
|
|
19
|
+
# Error is too long prefix
|
|
20
|
+
await Data(attr="important_data").pack_long()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def test_unicode_prefix_unique_id_respects_telegram_byte_limit(
|
|
24
|
+
callback_query_factory: CallbackQueryFactoryType,
|
|
25
|
+
) -> None:
|
|
26
|
+
class Data(LongCallbackData, prefix="🐍" * 10):
|
|
27
|
+
_storage = MemoryStorage()
|
|
28
|
+
|
|
29
|
+
attr: str
|
|
30
|
+
|
|
31
|
+
unique_id = _UniqueIDCallbackData.build(Data).pack()
|
|
32
|
+
assert len(unique_id.encode("utf-8")) <= 64
|
|
33
|
+
|
|
34
|
+
packed = await Data(attr="important_data" * 10).pack_long()
|
|
35
|
+
assert len(packed.encode("utf-8")) <= 64
|
|
36
|
+
|
|
37
|
+
result = await LongCallbackQueryFilter(callback_data=Data)(
|
|
38
|
+
callback_query_factory(packed)
|
|
39
|
+
)
|
|
40
|
+
assert result["callback_data"] == Data(attr="important_data" * 10)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from contextlib import AsyncExitStack, asynccontextmanager
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from aiogram_tool.tools.depend.types.enums import Scope
|
|
6
|
+
from aiogram_tool.tools.depend.utils.stack_manager import AsyncExitStackTransaction
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.parametrize("scope", [Scope.REQUEST, Scope.TRANSIENT])
|
|
10
|
+
async def test_dependency_receives_handler_exception(scope):
|
|
11
|
+
seen = []
|
|
12
|
+
|
|
13
|
+
@asynccontextmanager
|
|
14
|
+
async def dependency():
|
|
15
|
+
try:
|
|
16
|
+
yield
|
|
17
|
+
except RuntimeError as exc:
|
|
18
|
+
seen.append(exc)
|
|
19
|
+
raise
|
|
20
|
+
else:
|
|
21
|
+
seen.append("success")
|
|
22
|
+
|
|
23
|
+
error = RuntimeError("handler failed")
|
|
24
|
+
async with AsyncExitStack() as app_stack:
|
|
25
|
+
with pytest.raises(RuntimeError) as caught:
|
|
26
|
+
async with AsyncExitStackTransaction(app_stack) as transaction:
|
|
27
|
+
await transaction.enter_async_context(dependency(), scope)
|
|
28
|
+
raise error
|
|
29
|
+
assert caught.value is error
|
|
30
|
+
assert seen == [error]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def test_dependency_receives_success():
|
|
34
|
+
seen = []
|
|
35
|
+
|
|
36
|
+
@asynccontextmanager
|
|
37
|
+
async def dependency():
|
|
38
|
+
yield
|
|
39
|
+
seen.append("success")
|
|
40
|
+
|
|
41
|
+
async with AsyncExitStack() as app_stack:
|
|
42
|
+
async with AsyncExitStackTransaction(app_stack) as transaction:
|
|
43
|
+
await transaction.enter_async_context(dependency(), Scope.REQUEST)
|
|
44
|
+
assert seen == ["success"]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
|
-
from aiogram_tool.tools.callback_data.filter import LongCallbackData
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
async def test_unique_id_data_error() -> None:
|
|
7
|
-
|
|
8
|
-
class Data(LongCallbackData, prefix="LONG" * 13):
|
|
9
|
-
attr: str
|
|
10
|
-
|
|
11
|
-
with pytest.raises(ValueError):
|
|
12
|
-
# Error is too long prefix
|
|
13
|
-
await Data(attr="important_data").pack_long()
|
|
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
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/inner_middleware.py
RENAMED
|
File without changes
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/components/outer_middleware.py
RENAMED
|
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
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/depend/utils/registry_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/fixed_window.py
RENAMED
|
File without changes
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/sliding_window.py
RENAMED
|
File without changes
|
{aiogram_tool-1.2.3 → aiogram_tool-1.2.4}/aiogram_tool/tools/limit/rate_limit/token_bucket.py
RENAMED
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|