muffin-rest 13.0.1__tar.gz → 13.0.2__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 (39) hide show
  1. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/PKG-INFO +1 -1
  2. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/limits.py +11 -6
  3. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/pyproject.toml +1 -1
  4. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/LICENSE +0 -0
  5. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/README.md +0 -0
  6. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/__init__.py +0 -0
  7. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/api.py +0 -0
  8. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/errors.py +0 -0
  9. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/filters.py +0 -0
  10. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/handler.py +0 -0
  11. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/marshmallow.py +0 -0
  12. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/__init__.py +0 -0
  13. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/filters.py +0 -0
  14. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/schema.py +0 -0
  15. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/sorting.py +0 -0
  16. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/types.py +0 -0
  17. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/mongo/utils.py +0 -0
  18. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/openapi.py +0 -0
  19. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/options.py +0 -0
  20. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/__init__.py +0 -0
  21. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/filters.py +0 -0
  22. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/handler.py +0 -0
  23. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/openapi.py +0 -0
  24. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/options.py +0 -0
  25. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/schemas.py +0 -0
  26. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/sorting.py +0 -0
  27. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/types.py +0 -0
  28. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/peewee/utils.py +0 -0
  29. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/py.typed +0 -0
  30. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/redoc.html +0 -0
  31. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/schemas.py +0 -0
  32. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/sorting.py +0 -0
  33. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/sqlalchemy/__init__.py +0 -0
  34. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/sqlalchemy/filters.py +0 -0
  35. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/sqlalchemy/sorting.py +0 -0
  36. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/sqlalchemy/types.py +0 -0
  37. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/swagger.html +0 -0
  38. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/types.py +0 -0
  39. {muffin_rest-13.0.1 → muffin_rest-13.0.2}/muffin_rest/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: muffin-rest
3
- Version: 13.0.1
3
+ Version: 13.0.2
4
4
  Summary: The package provides enhanced support for writing REST APIs with Muffin framework
5
5
  License: MIT
6
6
  Keywords: rest,api,muffin,asgi,asyncio,trio
@@ -1,4 +1,5 @@
1
1
  import abc
2
+ from asyncio import Lock
2
3
  from time import time
3
4
  from typing import Any
4
5
 
@@ -13,13 +14,19 @@ class RateLimiter(abc.ABC):
13
14
  limit (int): The limit of requests.
14
15
  period (int): The period of time in seconds.
15
16
  """
17
+ self.lock = Lock()
16
18
  self.limit = limit
17
19
  self.period = period
18
20
 
19
- @abc.abstractmethod
20
21
  async def check(self, key: str) -> bool:
21
22
  """Check the request."""
22
- raise NotImplementedError
23
+ async with self.lock:
24
+ return await self._check(key)
25
+
26
+ @abc.abstractmethod
27
+ async def _check(self, key: str) -> bool:
28
+ """Check the request."""
29
+ raise NotImplementedError("Subclasses must implement this method.")
23
30
 
24
31
 
25
32
  class MemoryRateLimiter(RateLimiter):
@@ -29,7 +36,7 @@ class MemoryRateLimiter(RateLimiter):
29
36
  super().__init__(limit, **opts)
30
37
  self.storage: dict[Any, tuple[float, int]] = {}
31
38
 
32
- async def check(self, key: str) -> bool:
39
+ async def _check(self, key: str) -> bool:
33
40
  """Check the request."""
34
41
  now = time()
35
42
  storage = self.storage
@@ -53,8 +60,6 @@ class MemoryRateLimiter(RateLimiter):
53
60
  class RedisRateLimiter(RateLimiter):
54
61
  """Redis rate limiter."""
55
62
 
56
- # TODO: Asyncio lock
57
-
58
63
  def __init__(self, limit: int, *, redis, **opts):
59
64
  """Initialize the rate limiter.
60
65
 
@@ -66,7 +71,7 @@ class RedisRateLimiter(RateLimiter):
66
71
  super().__init__(limit, **opts)
67
72
  self.redis = redis
68
73
 
69
- async def check(self, key: str) -> bool:
74
+ async def _check(self, key: str) -> bool:
70
75
  """Check the request."""
71
76
  value = await self.redis.get(key)
72
77
  if value is None:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "muffin-rest"
3
- version = "13.0.1"
3
+ version = "13.0.2"
4
4
  description = "The package provides enhanced support for writing REST APIs with Muffin framework"
5
5
  readme = "README.md"
6
6
  homepage = "https://github.com/klen/muffin-rest"
File without changes
File without changes