muffin 0.93.3__py3-none-any.whl → 0.93.5__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.
muffin/app.py CHANGED
@@ -2,7 +2,6 @@
2
2
  from __future__ import annotations
3
3
 
4
4
  import logging
5
- from contextvars import ContextVar
6
5
  from inspect import isawaitable, stack
7
6
  from logging.config import dictConfig
8
7
  from typing import TYPE_CHECKING, Any, Dict, Mapping, Union
@@ -23,9 +22,6 @@ if TYPE_CHECKING:
23
22
  from muffin.plugins import BasePlugin
24
23
 
25
24
 
26
- background_task = ContextVar("background_task", default=None)
27
-
28
-
29
25
  class Application(BaseApp):
30
26
  """The Muffin Application."""
31
27
 
@@ -108,7 +104,7 @@ class Application(BaseApp):
108
104
  """Support background tasks."""
109
105
  await self.lifespan(scope, receive, send)
110
106
  bgtask = BACKGROUND_TASK.get()
111
- if bgtask is not None and isawaitable(bgtask):
107
+ if bgtask is not None:
112
108
  await bgtask
113
109
  BACKGROUND_TASK.set(None)
114
110
 
@@ -129,8 +125,8 @@ class Application(BaseApp):
129
125
  package_name = parent_frame.f_locals["__name__"]
130
126
  return import_submodules(package_name, *submodules)
131
127
 
132
- def run_background(self, task: Awaitable):
133
- """Await the given awaitable after the request is completed.
128
+ def run_after_response(self, task: Awaitable):
129
+ """Await the given awaitable after the response is completed.
134
130
 
135
131
  .. code-block:: python
136
132
 
@@ -147,11 +143,14 @@ class Application(BaseApp):
147
143
  async def send(request):
148
144
 
149
145
  # Schedule any awaitable for later execution
150
- app.run_background(send_email('user@email.com', 'Hello from Muffin!'))
146
+ app.run_after_response(send_email('user@email.com', 'Hello from Muffin!'))
151
147
 
152
148
  # Return response to a client immediately
153
149
  # The task will be executed after the response is sent
154
150
  return "OK"
155
151
 
156
152
  """
153
+ if not isawaitable(task):
154
+ raise TypeError("Task must be awaitable") # noqa: TRY003
155
+
157
156
  BACKGROUND_TASK.set(task)
muffin/handler.py CHANGED
@@ -15,21 +15,21 @@ if TYPE_CHECKING:
15
15
  from http_router import Router
16
16
 
17
17
 
18
-
19
18
  class HandlerMeta(type):
20
19
  """Prepare handlers."""
21
20
 
22
21
  def __new__(
23
- mcs: Type, name: str, bases: Tuple[Type], params: Dict[str, Any],
22
+ mcs: Type,
23
+ name: str,
24
+ bases: Tuple[type],
25
+ params: Dict[str, Any],
24
26
  ) -> Type["Handler"]:
25
27
  """Prepare a Handler Class."""
26
28
  cls: Type[Handler] = super().__new__(mcs, name, bases, params)
27
29
 
28
30
  # Ensure that the class methods are exist and iterable
29
31
  if not cls.methods:
30
- cls.methods = [
31
- method for method in HTTP_METHODS if method.lower() in cls.__dict__
32
- ]
32
+ cls.methods = [method for method in HTTP_METHODS if method.lower() in cls.__dict__]
33
33
 
34
34
  elif isinstance(cls.methods, str):
35
35
  cls.methods = [cls.methods]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: muffin
3
- Version: 0.93.3
3
+ Version: 0.93.5
4
4
  Summary: Muffin is a fast, simple and asyncronous web-framework for Python 3 (asyncio, trio, curio)
5
5
  Author-email: Kirill Klenov <horneds@gmail.com>
6
6
  License: MIT License
@@ -25,7 +25,7 @@ Classifier: Framework :: Trio
25
25
  Requires-Python: >=3.8
26
26
  Description-Content-Type: text/x-rst
27
27
  License-File: LICENSE
28
- Requires-Dist: asgi-tools (>=0.72.0)
28
+ Requires-Dist: asgi-tools (>=0.73.0)
29
29
  Requires-Dist: modconfig (>=1.2.1)
30
30
  Requires-Dist: ujson ; implementation_name == "cpython"
31
31
  Provides-Extra: dev
@@ -1,17 +1,17 @@
1
1
  muffin/__init__.py,sha256=F8Qp4ETX5FqI1832dj2moRAQ5hEb0TO9u4aRjSKXNjI,982
2
- muffin/app.py,sha256=MW4I7S4y8VZfiZUfBjp2ub4HLxRMoXw_mdVm0ps7FfA,4792
2
+ muffin/app.py,sha256=Q9EiTKZyUAJDp-Pm3xtBGxmrALz7gU92J9GX7Dp2mCo,4783
3
3
  muffin/constants.py,sha256=Q9Nm3Q4P3llL_irsvNQAkkD3CqlD4zKkGAM4nabzwrg,38
4
4
  muffin/errors.py,sha256=I-vKbMMBiMU07zPdKvoJKqA7s4xYAUA-4oZXrRMRzcM,701
5
- muffin/handler.py,sha256=storu1fRAVPbHoptuz93amRikRy1USyltknSFpBtyBo,3674
5
+ muffin/handler.py,sha256=c0b4pwsIF8jmqYwsWn3iuXR5BMwq2e6ASatGcPu9-N4,3667
6
6
  muffin/manage.py,sha256=2ozWcVRYsraO9DXz-awUdJ9LklmDl69mLRwgu-TpaaI,8734
7
7
  muffin/plugins.py,sha256=GppAovNL1oR0uGckR3IGquvj2w6Us8dLwlypY0UzB2w,2606
8
8
  muffin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  muffin/pytest.py,sha256=vnSEsQP8dJCFeS8nZklzAh7Stc3H-ng3jm6KlnAOMN0,2169
10
10
  muffin/types.py,sha256=wsUj5oAfqSZMoEf-wyFJLBlWa8Mc-eJGqKLr02HxuXE,153
11
11
  muffin/utils.py,sha256=4tdGNAmdEy6LPaf-5rLYx2YMZ5EOe6tXSqAC1GtG_TY,2422
12
- muffin-0.93.3.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
13
- muffin-0.93.3.dist-info/METADATA,sha256=WEkx8SH6H89wPcT1x0HoiaXWiESvNRzzs3MqBUPTqng,12021
14
- muffin-0.93.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
15
- muffin-0.93.3.dist-info/entry_points.txt,sha256=Q3DAZGQk-y5n7HmzJ4FrkNizqTRE2OVXsniPQXzS0Bg,87
16
- muffin-0.93.3.dist-info/top_level.txt,sha256=b_xNEFyizTmSqZWCTHwcvbycGyADewdsnaLXo2Pq1Ck,7
17
- muffin-0.93.3.dist-info/RECORD,,
12
+ muffin-0.93.5.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
13
+ muffin-0.93.5.dist-info/METADATA,sha256=3iPBBuFZGjt802Pq_L8meEmh9yEI2dNHT5OsfRycShI,12021
14
+ muffin-0.93.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
15
+ muffin-0.93.5.dist-info/entry_points.txt,sha256=Q3DAZGQk-y5n7HmzJ4FrkNizqTRE2OVXsniPQXzS0Bg,87
16
+ muffin-0.93.5.dist-info/top_level.txt,sha256=b_xNEFyizTmSqZWCTHwcvbycGyADewdsnaLXo2Pq1Ck,7
17
+ muffin-0.93.5.dist-info/RECORD,,