(p: str)
| 10519 | _action_lock = threading.Lock() |
| 10520 | |
| 10521 | def _rl_key(bucket: str, ident: str) -> str: |
| 10522 | return f"{bucket}:{ident or '?'}" |
| 10523 | |
| 10524 | def _rate_limit_hit(bucket: str, ident: str, limit: int, window_sec: int) -> bool: |
| 10525 | """Sliding-window rate limiter stored in memory for this process. |
| 10526 | |
| 10527 | Used for abusive login / signup / recovery / admin bursts. |
| 10528 | """ |
| 10529 | now = time.time() |
| 10530 | key = _rl_key(bucket, ident) |
| 10531 | with _action_lock: |
| 10532 | hits = [t for t in _action_hits.get(key, []) if (now - t) <= window_sec] |
| 10533 | if len(hits) >= limit: |
| 10534 | _action_hits[key] = hits |
| 10535 | return True |
| 10536 | hits.append(now) |
| 10537 | _action_hits[key] = hits |
| 10538 | return False |
no outgoing calls
no test coverage detected