Improve clarity of limiter_or_none logic.

This commit is contained in:
voussoir 2021-01-18 00:54:30 -08:00
parent e0771afa77
commit 7be7c2c908
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -569,14 +569,19 @@ def is_xor(*args):
return [bool(a) for a in args].count(True) == 1 return [bool(a) for a in args].count(True) == 1
def limiter_or_none(value): def limiter_or_none(value):
if isinstance(value, ratelimiter.Ratelimiter):
return value
if value is None:
return None
if isinstance(value, str): if isinstance(value, str):
value = bytestring.parsebytes(value) value = bytestring.parsebytes(value)
if isinstance(value, ratelimiter.Ratelimiter):
limiter = value if not isinstance(value, (int, float)):
elif value is not None: raise TypeError(type(value))
limiter = ratelimiter.Ratelimiter(allowance=value, period=1)
else: limiter = ratelimiter.Ratelimiter(allowance=value, period=1)
limiter = None
return limiter return limiter
def new_root(filepath, root): def new_root(filepath, root):