aiogram-webhook 3.0.0__tar.gz → 3.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.
Files changed (41) hide show
  1. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/PKG-INFO +1 -1
  2. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/pyproject.toml +1 -1
  3. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/base.py +12 -4
  4. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/multi.py +1 -3
  5. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/single.py +1 -3
  6. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/token.py +1 -3
  7. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/web/fastapi.py +5 -21
  8. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/README.md +0 -0
  9. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/__init__.py +0 -0
  10. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/configs/__init__.py +0 -0
  11. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/configs/bot.py +0 -0
  12. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/configs/webhook.py +0 -0
  13. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/__init__.py +0 -0
  14. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/errors.py +0 -0
  15. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/engines/target.py +0 -0
  16. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/errors.py +0 -0
  17. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/logs.py +0 -0
  18. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/py.typed +0 -0
  19. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/__init__.py +0 -0
  20. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/config.py +0 -0
  21. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/errors.py +0 -0
  22. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/params.py +0 -0
  23. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/path.py +0 -0
  24. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/query.py +0 -0
  25. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/route.py +0 -0
  26. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/route/url.py +0 -0
  27. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/__init__.py +0 -0
  28. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/checks/__init__.py +0 -0
  29. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/checks/check.py +0 -0
  30. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/checks/ip.py +0 -0
  31. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/errors.py +0 -0
  32. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/secret_token.py +0 -0
  33. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/security/security.py +0 -0
  34. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/tasks.py +0 -0
  35. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/utils/__init__.py +0 -0
  36. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/utils/_payload.py +0 -0
  37. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/utils/config.py +0 -0
  38. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/web/__init__.py +0 -0
  39. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/web/_starlette.py +0 -0
  40. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/web/aiohttp.py +0 -0
  41. {aiogram_webhook-3.0.0 → aiogram_webhook-3.0.1}/src/aiogram_webhook/web/base.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aiogram-webhook
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: A python library for integrating webhook support with multiple web frameworks in aiogram. Organizes bot operation via webhooks for both single and multi-bot setups.
5
5
  Keywords: aiogram,multibot,telegram,webhook,fastapi,aiohttp
6
6
  Author: m-xim
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aiogram-webhook"
3
- version = "3.0.0"
3
+ version = "3.0.1"
4
4
  description = "A python library for integrating webhook support with multiple web frameworks in aiogram. Organizes bot operation via webhooks for both single and multi-bot setups."
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -1,8 +1,10 @@
1
1
  import warnings
2
2
  from abc import ABC, abstractmethod
3
+ from collections.abc import AsyncGenerator
4
+ from contextlib import asynccontextmanager
3
5
  from typing import Any, Generic, TypeVar
4
6
 
5
- from aiogram import Bot
7
+ from aiogram import Bot, Dispatcher
6
8
  from aiogram.methods import TelegramMethod
7
9
 
8
10
  from aiogram_webhook.engines.errors import (
@@ -31,9 +33,7 @@ FrameworkResponseT = TypeVar("FrameworkResponseT")
31
33
  class BaseWebhookEngine(ABC, Generic[AppT, RawRequestT, FrameworkResponseT]):
32
34
  def __init__(
33
35
  self,
34
- dispatcher,
35
- /,
36
- *,
36
+ dispatcher: Dispatcher,
37
37
  web: WebAdapter[AppT, RawRequestT, FrameworkResponseT],
38
38
  route: Route,
39
39
  security: Security | None = None,
@@ -111,6 +111,14 @@ class BaseWebhookEngine(ABC, Generic[AppT, RawRequestT, FrameworkResponseT]):
111
111
  self._is_shutting_down = True
112
112
  await self._on_shutdown(app, *args, **kwargs)
113
113
 
114
+ @asynccontextmanager
115
+ async def lifespan(self, app: AppT) -> AsyncGenerator[None, Any]:
116
+ try:
117
+ await self.on_startup(app=app)
118
+ yield
119
+ finally:
120
+ await self.on_shutdown(app=app)
121
+
114
122
  @abstractmethod
115
123
  async def _on_startup(self, app: AppT, *args: Any, **kwargs: Any) -> None:
116
124
  raise NotImplementedError
@@ -21,8 +21,6 @@ class BaseMultiBotEngine(
21
21
  def __init__(
22
22
  self,
23
23
  dispatcher,
24
- /,
25
- *,
26
24
  web: WebAdapter[AppT, RawRequestT, FrameworkResponseT],
27
25
  route: Route,
28
26
  security: Security | None = None,
@@ -34,7 +32,7 @@ class BaseMultiBotEngine(
34
32
  self._bots: dict[int, Bot] = {}
35
33
  self.webhook_config = webhook_config or WebhookConfig()
36
34
  super().__init__(
37
- dispatcher,
35
+ dispatcher=dispatcher,
38
36
  web=web,
39
37
  route=route,
40
38
  security=security,
@@ -19,8 +19,6 @@ class SingleBotEngine(
19
19
  self,
20
20
  dispatcher,
21
21
  bot: Bot,
22
- /,
23
- *,
24
22
  web: WebAdapter[AppT, RawRequestT, FrameworkResponseT],
25
23
  route: Route,
26
24
  security=None,
@@ -31,7 +29,7 @@ class SingleBotEngine(
31
29
  self._task_tracker = TaskTracker()
32
30
 
33
31
  super().__init__(
34
- dispatcher,
32
+ dispatcher=dispatcher,
35
33
  web=web,
36
34
  route=route,
37
35
  security=security,
@@ -24,8 +24,6 @@ class TokenEngine(
24
24
  def __init__(
25
25
  self,
26
26
  dispatcher,
27
- /,
28
- *,
29
27
  web: WebAdapter[AppT, RawRequestT, FrameworkResponseT],
30
28
  route: Route,
31
29
  security=None,
@@ -35,7 +33,7 @@ class TokenEngine(
35
33
  shutdown_timeout: float = 10.0,
36
34
  ) -> None:
37
35
  super().__init__(
38
- dispatcher,
36
+ dispatcher=dispatcher,
39
37
  web=web,
40
38
  route=route,
41
39
  security=security,
@@ -1,12 +1,10 @@
1
- from collections.abc import AsyncIterator, Mapping
2
- from contextlib import asynccontextmanager
1
+ from collections.abc import Mapping
3
2
  from typing import Any
4
3
 
5
4
  from aiohttp import Payload
6
- from fastapi import APIRouter, FastAPI, Request, Response
5
+ from fastapi import FastAPI, Request, Response
7
6
  from fastapi.responses import JSONResponse
8
7
  from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
9
- from starlette.types import Lifespan
10
8
 
11
9
  from aiogram_webhook.web._starlette import AiohttpPayloadResponse
12
10
  from aiogram_webhook.web.base import (
@@ -60,33 +58,19 @@ class FastAPIAdapter(WebAdapter[FastAPI, Request, Response]):
60
58
  def bind_request(self, request: Request) -> WebRequest[Request]:
61
59
  return FastAPIWebRequest(request)
62
60
 
63
- @staticmethod
64
- def _build_lifespan(on_startup: LifecycleCallback, on_shutdown: LifecycleCallback) -> Lifespan[FastAPI]:
65
- @asynccontextmanager
66
- async def lifespan(app: FastAPI) -> AsyncIterator[None]:
67
- await on_startup(app)
68
- try:
69
- yield
70
- finally:
71
- await on_shutdown(app)
72
-
73
- return lifespan
74
-
75
61
  def register(
76
62
  self,
77
63
  app: FastAPI,
78
64
  path: str,
79
65
  handler: WebHandler[Request, Response],
80
66
  *,
81
- on_startup: LifecycleCallback,
82
- on_shutdown: LifecycleCallback,
67
+ on_startup: LifecycleCallback, # noqa: ARG002
68
+ on_shutdown: LifecycleCallback, # noqa: ARG002
83
69
  ) -> None:
84
70
  async def endpoint(request: Request) -> Response:
85
71
  return await handler(self.bind_request(request))
86
72
 
87
- router = APIRouter(lifespan=self._build_lifespan(on_startup, on_shutdown))
88
- router.add_api_route(path=path, endpoint=endpoint, methods=["POST"])
89
- app.include_router(router)
73
+ app.add_api_route(path=path, endpoint=endpoint, methods=["POST"])
90
74
 
91
75
  def json_response(
92
76
  self, status_code: int, data: dict[str, str] | None = None, headers: Mapping[str, str] | None = None