Total Complexity | 2 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | |||
3 | |||
4 | """ |
||
5 | |||
6 | |||
7 | Created on 10.09.2021 |
||
8 | |||
9 | @author: Nikita |
||
10 | |||
11 | |||
12 | """ |
||
13 | |||
14 | |||
15 | def rate_limit(limit: int, key=None): |
||
16 | |||
17 | """ |
||
18 | |||
19 | Decorator for configuring rate limit and key in different functions. |
||
20 | |||
21 | """ |
||
22 | |||
23 | def decorator(func): |
||
24 | |||
25 | setattr(func, 'throttling_rate_limit', limit) |
||
26 | |||
27 | if key: |
||
28 | setattr(func, 'throttling_key', key) |
||
29 | |||
30 | return func |
||
31 | |||
32 | return decorator |
||
33 |