MCPcopy
hub / github.com/AstrBotDevs/AstrBot / _AuthRateLimiter

Class _AuthRateLimiter

astrbot/dashboard/server.py:51–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51class _AuthRateLimiter:
52 def __init__(self, capacity: int, refill_rate: float):
53 self.capacity = capacity
54 self.refill_rate = refill_rate
55 self.tokens = float(capacity)
56 self.last_refill = time.monotonic()
57 self.last_accessed = time.monotonic()
58 self.lock = asyncio.Lock()
59
60 async def acquire(self) -> bool:
61 async with self.lock:
62 now = time.monotonic()
63 elapsed = now - self.last_refill
64 self.tokens = min(self.capacity, self.tokens + elapsed * self.refill_rate)
65 self.last_refill = now
66 self.last_accessed = now
67 if self.tokens >= 1:
68 self.tokens -= 1
69 return True
70 return False
71
72
73class _RateLimiterRegistry:

Callers 1

get_or_createMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected