Check if the IP address is rate-limited. Returns True if the number of recent requests exceeds RATE_LIMIT_COUNT. Always returns False if RATE_LIMIT_ENABLE is False.
(ip: str)
| 34 | |
| 35 | |
| 36 | def is_blocked(ip: str) -> bool: |
| 37 | """ |
| 38 | Check if the IP address is rate-limited. |
| 39 | Returns True if the number of recent requests exceeds RATE_LIMIT_COUNT. |
| 40 | Always returns False if RATE_LIMIT_ENABLE is False. |
| 41 | """ |
| 42 | if not RATE_LIMIT_ENABLE: |
| 43 | return False |
| 44 | |
| 45 | key, now = _key(ip), _now_us() |
| 46 | |
| 47 | count = cache.zcount(key, now - WINDOW_US, now) |
| 48 | return count > RATE_LIMIT_COUNT |
| 49 | |
| 50 | |
| 51 | def clear(ip: str) -> None: |