limits 4.0.0__py3-none-any.whl → 4.0.1__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 +3 -3
- limits/aio/storage/mongodb.py +20 -14
- limits/storage/__init__.py +3 -3
- limits/storage/memcached.py +1 -2
- limits/storage/mongodb.py +20 -13
- {limits-4.0.0.dist-info → limits-4.0.1.dist-info}/METADATA +1 -1
- {limits-4.0.0.dist-info → limits-4.0.1.dist-info}/RECORD +10 -10
- {limits-4.0.0.dist-info → limits-4.0.1.dist-info}/LICENSE.txt +0 -0
- {limits-4.0.0.dist-info → limits-4.0.1.dist-info}/WHEEL +0 -0
- {limits-4.0.0.dist-info → limits-4.0.1.dist-info}/top_level.txt +0 -0
limits/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2025-01-
|
|
11
|
+
"date": "2025-01-16T11:38:03-0800",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "4.0.
|
|
14
|
+
"full-revisionid": "074be17ab3008f50de700e996d243ba85580b058",
|
|
15
|
+
"version": "4.0.1"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
limits/aio/storage/mongodb.py
CHANGED
|
@@ -3,12 +3,12 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import datetime
|
|
5
5
|
import time
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import cast
|
|
7
7
|
|
|
8
8
|
from deprecated.sphinx import versionadded, versionchanged
|
|
9
9
|
|
|
10
10
|
from limits.aio.storage.base import MovingWindowSupport, Storage
|
|
11
|
-
from limits.typing import Dict, Optional, ParamSpec, Tuple, Type, TypeVar, Union
|
|
11
|
+
from limits.typing import Dict, List, Optional, ParamSpec, Tuple, Type, TypeVar, Union
|
|
12
12
|
from limits.util import get_dependency
|
|
13
13
|
|
|
14
14
|
P = ParamSpec("P")
|
|
@@ -281,23 +281,29 @@ class MongoDBStorage(Storage, MovingWindowSupport):
|
|
|
281
281
|
|
|
282
282
|
timestamp = time.time()
|
|
283
283
|
try:
|
|
284
|
-
updates: Dict[
|
|
285
|
-
|
|
284
|
+
updates: Dict[
|
|
285
|
+
str,
|
|
286
|
+
Dict[str, Union[datetime.datetime, Dict[str, Union[List[float], int]]]],
|
|
287
|
+
] = {
|
|
288
|
+
"$push": {
|
|
289
|
+
"entries": {
|
|
290
|
+
"$each": [timestamp] * amount,
|
|
291
|
+
"$position": 0,
|
|
292
|
+
"$slice": limit,
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
"$set": {
|
|
296
|
+
"expireAt": (
|
|
297
|
+
datetime.datetime.now(datetime.timezone.utc)
|
|
298
|
+
+ datetime.timedelta(seconds=expiry)
|
|
299
|
+
)
|
|
300
|
+
},
|
|
286
301
|
}
|
|
287
302
|
|
|
288
|
-
updates["$set"] = {
|
|
289
|
-
"expireAt": (
|
|
290
|
-
datetime.datetime.now(datetime.timezone.utc)
|
|
291
|
-
+ datetime.timedelta(seconds=expiry)
|
|
292
|
-
)
|
|
293
|
-
}
|
|
294
|
-
updates["$push"]["entries"]["$each"] = [timestamp] * amount
|
|
295
303
|
await self.database[self.__collection_mapping["windows"]].update_one(
|
|
296
304
|
{
|
|
297
305
|
"_id": key,
|
|
298
|
-
"entries
|
|
299
|
-
"$not": {"$gte": timestamp - expiry}
|
|
300
|
-
},
|
|
306
|
+
f"entries.{limit - amount}": {"$not": {"$gte": timestamp - expiry}},
|
|
301
307
|
},
|
|
302
308
|
updates,
|
|
303
309
|
upsert=True,
|
limits/storage/__init__.py
CHANGED
|
@@ -32,9 +32,9 @@ def storage_from_string(
|
|
|
32
32
|
|
|
33
33
|
from limits.storage import storage_from_string
|
|
34
34
|
|
|
35
|
-
memory =
|
|
36
|
-
memcached =
|
|
37
|
-
redis =
|
|
35
|
+
memory = storage_from_string("memory://")
|
|
36
|
+
memcached = storage_from_string("memcached://localhost:11211")
|
|
37
|
+
redis = storage_from_string("redis://localhost:6379")
|
|
38
38
|
|
|
39
39
|
The same function can be used to construct the :ref:`storage:async storage`
|
|
40
40
|
variants, for example::
|
limits/storage/memcached.py
CHANGED
|
@@ -77,8 +77,7 @@ class MemcachedStorage(Storage):
|
|
|
77
77
|
|
|
78
78
|
if not get_dependency(self.library):
|
|
79
79
|
raise ConfigurationError(
|
|
80
|
-
"memcached prerequisite not available."
|
|
81
|
-
" please install %s" % self.library
|
|
80
|
+
"memcached prerequisite not available. please install %s" % self.library
|
|
82
81
|
) # pragma: no cover
|
|
83
82
|
self.local_storage = threading.local()
|
|
84
83
|
self.local_storage.storage = None
|
limits/storage/mongodb.py
CHANGED
|
@@ -3,12 +3,13 @@ from __future__ import annotations
|
|
|
3
3
|
import datetime
|
|
4
4
|
import time
|
|
5
5
|
from abc import ABC, abstractmethod
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import cast
|
|
7
7
|
|
|
8
8
|
from deprecated.sphinx import versionadded, versionchanged
|
|
9
9
|
|
|
10
10
|
from limits.typing import (
|
|
11
11
|
Dict,
|
|
12
|
+
List,
|
|
12
13
|
MongoClient,
|
|
13
14
|
MongoCollection,
|
|
14
15
|
MongoDatabase,
|
|
@@ -256,23 +257,29 @@ class MongoDBStorageBase(Storage, MovingWindowSupport, ABC):
|
|
|
256
257
|
|
|
257
258
|
timestamp = time.time()
|
|
258
259
|
try:
|
|
259
|
-
updates: Dict[
|
|
260
|
-
|
|
260
|
+
updates: Dict[
|
|
261
|
+
str,
|
|
262
|
+
Dict[str, Union[datetime.datetime, Dict[str, Union[List[float], int]]]],
|
|
263
|
+
] = {
|
|
264
|
+
"$push": {
|
|
265
|
+
"entries": {
|
|
266
|
+
"$each": [timestamp] * amount,
|
|
267
|
+
"$position": 0,
|
|
268
|
+
"$slice": limit,
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"$set": {
|
|
272
|
+
"expireAt": (
|
|
273
|
+
datetime.datetime.now(datetime.timezone.utc)
|
|
274
|
+
+ datetime.timedelta(seconds=expiry)
|
|
275
|
+
)
|
|
276
|
+
},
|
|
261
277
|
}
|
|
262
278
|
|
|
263
|
-
updates["$set"] = {
|
|
264
|
-
"expireAt": (
|
|
265
|
-
datetime.datetime.now(datetime.timezone.utc)
|
|
266
|
-
+ datetime.timedelta(seconds=expiry)
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
updates["$push"]["entries"]["$each"] = [timestamp] * amount
|
|
270
279
|
self.windows.update_one(
|
|
271
280
|
{
|
|
272
281
|
"_id": key,
|
|
273
|
-
"entries
|
|
274
|
-
"$not": {"$gte": timestamp - expiry}
|
|
275
|
-
},
|
|
282
|
+
f"entries.{limit - amount}": {"$not": {"$gte": timestamp - expiry}},
|
|
276
283
|
},
|
|
277
284
|
updates,
|
|
278
285
|
upsert=True,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
limits/__init__.py,sha256=j_yVhgN9pdz8o5rQjVwdJTBSq8F-CTzof9kkiYgjRbw,728
|
|
2
|
-
limits/_version.py,sha256=
|
|
2
|
+
limits/_version.py,sha256=pB8_a1HHuX7Bo8LVuoQ_8GjLU5i4z56J1tr986TiLUA,497
|
|
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
|
|
@@ -14,24 +14,24 @@ limits/aio/storage/base.py,sha256=V1Ur9Cu29_vP5IYBIsWHTgrc4riW8FEyz5Dcvv6fPoc,48
|
|
|
14
14
|
limits/aio/storage/etcd.py,sha256=krqjWujvybuaFa2g_FkPr2ZtX9Ac1-oJzErfGW3h27o,4783
|
|
15
15
|
limits/aio/storage/memcached.py,sha256=n8b9GVtXMWdc-w4-xP1_MPJ9dgVcgoJ5j53mTdU6E3E,4799
|
|
16
16
|
limits/aio/storage/memory.py,sha256=4ah9RpE5r7Q2yOLT-OndhP4ZHmvcwV3rKvCicnK2CJc,5845
|
|
17
|
-
limits/aio/storage/mongodb.py,sha256=
|
|
17
|
+
limits/aio/storage/mongodb.py,sha256=pC5Ng-5PlV5u1EQlgITfetLvpL4mitcxaaZ_uokwUs0,10846
|
|
18
18
|
limits/aio/storage/redis.py,sha256=JQm4pkwynSo1k6wFVB7SyRsh7yav0_61Px1FqUwuGl4,15658
|
|
19
19
|
limits/resources/redis/lua_scripts/acquire_moving_window.lua,sha256=5CFJX7D6T6RG5SFr6eVZ6zepmI1EkGWmKeVEO4QNrWo,483
|
|
20
20
|
limits/resources/redis/lua_scripts/clear_keys.lua,sha256=zU0cVfLGmapRQF9x9u0GclapM_IB2pJLszNzVQ1QRK4,184
|
|
21
21
|
limits/resources/redis/lua_scripts/incr_expire.lua,sha256=Uq9NcrrcDI-F87TDAJexoSJn2SDgeXIUEYozCp9S3oA,195
|
|
22
22
|
limits/resources/redis/lua_scripts/moving_window.lua,sha256=5hUZghISDh8Cbg8HJediM_OKjjNMF-0CBywWmsc93vA,430
|
|
23
|
-
limits/storage/__init__.py,sha256=
|
|
23
|
+
limits/storage/__init__.py,sha256=_ozbLZtZDVRamfNe4clxcmYbM9Gbu8FzuuAeWQAi_ZA,2588
|
|
24
24
|
limits/storage/base.py,sha256=E7ZInoGZqoM1QIpd1f8lvytlic4sMOQdl_eTzD-mlWk,4631
|
|
25
25
|
limits/storage/etcd.py,sha256=Q1tndCAAJp0jnir-b-ZBN3-7Kf3v_uwNAqQJLmqB96Q,4440
|
|
26
|
-
limits/storage/memcached.py,sha256=
|
|
26
|
+
limits/storage/memcached.py,sha256=4xgcSI7l02KbHP0P_ChFgx5ytDqiby6-kwfJ6_5lua4,6618
|
|
27
27
|
limits/storage/memory.py,sha256=ButyS6v7o7DB55bwM3CltFK4Fc5mwKuFEBPgat51CXU,5550
|
|
28
|
-
limits/storage/mongodb.py,sha256=
|
|
28
|
+
limits/storage/mongodb.py,sha256=LmrkLOlMMveI4hnv69yMOQhrXUqp6RMvdjXkvTiE4DY,9979
|
|
29
29
|
limits/storage/redis.py,sha256=R7UbE5ng1NjIHEO17gu-vIZ4qgy91JctbPYGEkZ2iM0,8483
|
|
30
30
|
limits/storage/redis_cluster.py,sha256=MsiEpwHphQd0P88AwGw1NVSi3UwVrhsg-pvzkHxU2kw,3739
|
|
31
31
|
limits/storage/redis_sentinel.py,sha256=665CvL3UZYB2sB_vVkZ4CCaPKcbIXvQUWuDWnBoSOLU,4124
|
|
32
32
|
limits/storage/registry.py,sha256=xcBcxuu6srqmoS4WqDpkCXnRLB19ctH98v21P8S9kS8,708
|
|
33
|
-
limits-4.0.
|
|
34
|
-
limits-4.0.
|
|
35
|
-
limits-4.0.
|
|
36
|
-
limits-4.0.
|
|
37
|
-
limits-4.0.
|
|
33
|
+
limits-4.0.1.dist-info/LICENSE.txt,sha256=T6i7kq7F5gIPfcno9FCxU5Hcwm22Bjq0uHZV3ElcjsQ,1061
|
|
34
|
+
limits-4.0.1.dist-info/METADATA,sha256=EzpDuoZfOrB3xjvhv-IHK5Q6-R_6-vH5FnUEoJ-ohdI,7662
|
|
35
|
+
limits-4.0.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
36
|
+
limits-4.0.1.dist-info/top_level.txt,sha256=C7g5ahldPoU2s6iWTaJayUrbGmPK1d6e9t5Nn0vQ2jM,7
|
|
37
|
+
limits-4.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|