limits 3.12.0__py3-none-any.whl → 3.13.0__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.
limits/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-05-12T10:01:06-0700",
11
+ "date": "2024-06-22T18:39:54-0700",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "ff28751a2326de0ad6a978e316397534acf29b81",
15
- "version": "3.12.0"
14
+ "full-revisionid": "7b87c4d37659ae5fe0a8bf7216bfff789facd5f3",
15
+ "version": "3.13.0"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
limits/aio/strategies.py CHANGED
@@ -29,13 +29,14 @@ class RateLimiter(ABC):
29
29
  raise NotImplementedError
30
30
 
31
31
  @abstractmethod
32
- async def test(self, item: RateLimitItem, *identifiers: str) -> bool:
32
+ async def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
33
33
  """
34
34
  Check if the rate limit can be consumed
35
35
 
36
36
  :param item: the rate limit item
37
37
  :param identifiers: variable list of strings to uniquely identify the
38
38
  limit
39
+ :param cost: The expected cost to be consumed, default 1
39
40
  """
40
41
  raise NotImplementedError
41
42
 
@@ -86,13 +87,14 @@ class MovingWindowRateLimiter(RateLimiter):
86
87
  item.key_for(*identifiers), item.amount, item.get_expiry(), amount=cost
87
88
  )
88
89
 
89
- async def test(self, item: RateLimitItem, *identifiers: str) -> bool:
90
+ async def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
90
91
  """
91
92
  Check if the rate limit can be consumed
92
93
 
93
94
  :param item: the rate limit item
94
95
  :param identifiers: variable list of strings to uniquely identify the
95
96
  limit
97
+ :param cost: The expected cost to be consumed, default 1
96
98
  """
97
99
  res = await cast(MovingWindowSupport, self.storage).get_moving_window(
98
100
  item.key_for(*identifiers),
@@ -101,7 +103,7 @@ class MovingWindowRateLimiter(RateLimiter):
101
103
  )
102
104
  amount = res[1]
103
105
 
104
- return amount < item.amount
106
+ return amount <= item.amount - cost
105
107
 
106
108
  async def get_window_stats(
107
109
  self, item: RateLimitItem, *identifiers: str
@@ -147,16 +149,19 @@ class FixedWindowRateLimiter(RateLimiter):
147
149
  <= item.amount
148
150
  )
149
151
 
150
- async def test(self, item: RateLimitItem, *identifiers: str) -> bool:
152
+ async def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
151
153
  """
152
154
  Check if the rate limit can be consumed
153
155
 
154
156
  :param item: the rate limit item
155
157
  :param identifiers: variable list of strings to uniquely identify the
156
158
  limit
159
+ :param cost: The expected cost to be consumed, default 1
157
160
  """
158
161
 
159
- return await self.storage.get(item.key_for(*identifiers)) < item.amount
162
+ return (
163
+ await self.storage.get(item.key_for(*identifiers)) < item.amount - cost + 1
164
+ )
160
165
 
161
166
  async def get_window_stats(
162
167
  self, item: RateLimitItem, *identifiers: str
limits/strategies.py CHANGED
@@ -28,13 +28,14 @@ class RateLimiter(metaclass=ABCMeta):
28
28
  raise NotImplementedError
29
29
 
30
30
  @abstractmethod
31
- def test(self, item: RateLimitItem, *identifiers: str) -> bool:
31
+ def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
32
32
  """
33
33
  Check the rate limit without consuming from it.
34
34
 
35
35
  :param item: The rate limit item
36
36
  :param identifiers: variable list of strings to uniquely identify this
37
37
  instance of the limit
38
+ :param cost: The expected cost to be consumed, default 1
38
39
  """
39
40
  raise NotImplementedError
40
41
 
@@ -84,13 +85,14 @@ class MovingWindowRateLimiter(RateLimiter):
84
85
  item.key_for(*identifiers), item.amount, item.get_expiry(), amount=cost
85
86
  )
86
87
 
87
- def test(self, item: RateLimitItem, *identifiers: str) -> bool:
88
+ def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
88
89
  """
89
90
  Check if the rate limit can be consumed
90
91
 
91
92
  :param item: The rate limit item
92
93
  :param identifiers: variable list of strings to uniquely identify this
93
94
  instance of the limit
95
+ :param cost: The expected cost to be consumed, default 1
94
96
  """
95
97
 
96
98
  return (
@@ -99,7 +101,7 @@ class MovingWindowRateLimiter(RateLimiter):
99
101
  item.amount,
100
102
  item.get_expiry(),
101
103
  )[1]
102
- < item.amount
104
+ <= item.amount - cost
103
105
  )
104
106
 
105
107
  def get_window_stats(self, item: RateLimitItem, *identifiers: str) -> WindowStats:
@@ -144,16 +146,17 @@ class FixedWindowRateLimiter(RateLimiter):
144
146
  <= item.amount
145
147
  )
146
148
 
147
- def test(self, item: RateLimitItem, *identifiers: str) -> bool:
149
+ def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
148
150
  """
149
151
  Check if the rate limit can be consumed
150
152
 
151
153
  :param item: The rate limit item
152
154
  :param identifiers: variable list of strings to uniquely identify this
153
155
  instance of the limit
156
+ :param cost: The expected cost to be consumed, default 1
154
157
  """
155
158
 
156
- return self.storage.get(item.key_for(*identifiers)) < item.amount
159
+ return self.storage.get(item.key_for(*identifiers)) < item.amount - cost + 1
157
160
 
158
161
  def get_window_stats(self, item: RateLimitItem, *identifiers: str) -> WindowStats:
159
162
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: limits
3
- Version: 3.12.0
3
+ Version: 3.13.0
4
4
  Summary: Rate limiting utilities
5
5
  Home-page: https://limits.readthedocs.org
6
6
  Author: Ali-Akber Saifee
@@ -1,14 +1,14 @@
1
1
  limits/__init__.py,sha256=j_yVhgN9pdz8o5rQjVwdJTBSq8F-CTzof9kkiYgjRbw,728
2
- limits/_version.py,sha256=hEL57l9rkTEoBd9jvOB4z-OkCjpEs9jAM_ocoojdL6k,498
2
+ limits/_version.py,sha256=WegVz4YKhtYN102E8QvX81l0oVnN2UGchIOm2eVCePg,498
3
3
  limits/errors.py,sha256=xCKGOVJiD-g8FlsQQb17AW2pTUvalYSuizPpvEVoYJE,626
4
4
  limits/limits.py,sha256=ZsXESq2e1ji7c2ZKjSkIAasCjiLdjVLPUa9oah_I8U4,4943
5
5
  limits/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- limits/strategies.py,sha256=7pr2V34KdOEfxnYOf882Cl2qKY-KK6HwKjdYo_IsD4c,6690
6
+ limits/strategies.py,sha256=Zy6PIhkysPbxnMzFjyXEsxMM6jhRoQ5XT5WskTNruK0,6949
7
7
  limits/typing.py,sha256=nwJLek44QIg3869AbOSvPwotfp6JR7vEHz_UgZBiqgg,3287
8
8
  limits/util.py,sha256=xMRR5bKksYcnzY0H0xORDGvRFF5btiBognY2sSd38NE,5743
9
9
  limits/version.py,sha256=YwkF3dtq1KGzvmL3iVGctA8NNtGlK_0arrzZkZGVjUs,47
10
10
  limits/aio/__init__.py,sha256=IOetunwQy1c5GefzitK8lewbTzHGiE-kmE9NlqSdr3U,82
11
- limits/aio/strategies.py,sha256=REaQ-lqgqkN5wrFZ26AZ3sCHO8oZBL_mWhI6nMRaBz8,6485
11
+ limits/aio/strategies.py,sha256=SHjmJnmy7Nh4tBydkA-0qPaULYcLOAM91T4RPybq0Sg,6768
12
12
  limits/aio/storage/__init__.py,sha256=CbtuSlVl1jPyN_vsEI_ApWblDblVaL46xcZ2M_oM0V8,595
13
13
  limits/aio/storage/base.py,sha256=xdYpBBonyMjxE9iT-2oZjm6x29aDU6Xd09MeBYbZcMo,4817
14
14
  limits/aio/storage/etcd.py,sha256=Rjb_EYKFRr4F2Z6zvAPP9vQOyXJQHaju3VjxxUs75_c,4791
@@ -30,8 +30,8 @@ limits/storage/redis.py,sha256=3zJ1gDMDepT_pGN9d2aAN7Pea7tMBI49VK60IHv-Ooc,8452
30
30
  limits/storage/redis_cluster.py,sha256=KwhWV0v3_TliRyS3OU15IlpeC8gRQr29U4FkcME01fo,5380
31
31
  limits/storage/redis_sentinel.py,sha256=7PVB0hBl0I_enhN_h9QSJTE7zGuYtjkebotTqxm2iZo,3875
32
32
  limits/storage/registry.py,sha256=xcBcxuu6srqmoS4WqDpkCXnRLB19ctH98v21P8S9kS8,708
33
- limits-3.12.0.dist-info/LICENSE.txt,sha256=T6i7kq7F5gIPfcno9FCxU5Hcwm22Bjq0uHZV3ElcjsQ,1061
34
- limits-3.12.0.dist-info/METADATA,sha256=Evty_7zeDjM5XTCfNpdERwhzmfMnOU36NdkHiQE841s,7170
35
- limits-3.12.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
36
- limits-3.12.0.dist-info/top_level.txt,sha256=C7g5ahldPoU2s6iWTaJayUrbGmPK1d6e9t5Nn0vQ2jM,7
37
- limits-3.12.0.dist-info/RECORD,,
33
+ limits-3.13.0.dist-info/LICENSE.txt,sha256=T6i7kq7F5gIPfcno9FCxU5Hcwm22Bjq0uHZV3ElcjsQ,1061
34
+ limits-3.13.0.dist-info/METADATA,sha256=vQsvBw6YR-jK6cCIusRrIjc-UG-aSL4PoHqFfYKzvjE,7170
35
+ limits-3.13.0.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
36
+ limits-3.13.0.dist-info/top_level.txt,sha256=C7g5ahldPoU2s6iWTaJayUrbGmPK1d6e9t5Nn0vQ2jM,7
37
+ limits-3.13.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5