Files
patrickandClaude Sonnet 5.5 9c4f7366eb
test / pytest (3.11) (push) Canceled after 0s
test / pytest (3.13) (push) Canceled after 0s
feat: Phase 6 prompt versioning with test area, retention
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 02:17:01 +01:00

19 lines
654 B
Python

import time
from typing import Callable
from ..alerts import SlidingWindowLimiter
from .constants import TEST_RATE_LIMIT, TEST_RATE_WINDOW
class UserRateLimiter:
def __init__(self, limit: int = TEST_RATE_LIMIT, window: float = TEST_RATE_WINDOW,
clock: Callable[[], float] = time.monotonic):
self._limit = limit
self._window = window
self._clock = clock
self._by_user: dict[str, SlidingWindowLimiter] = {}
def try_acquire(self, user: str) -> bool:
limiter = self._by_user.setdefault(user, SlidingWindowLimiter(self._clock, self._window))
return limiter.try_acquire(self._limit)