Improve clarity of limiter_or_none logic.
This commit is contained in:
parent
e0771afa77
commit
7be7c2c908
1 changed files with 11 additions and 6 deletions
|
@ -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)
|
limiter = ratelimiter.Ratelimiter(allowance=value, period=1)
|
||||||
else:
|
|
||||||
limiter = None
|
|
||||||
return limiter
|
return limiter
|
||||||
|
|
||||||
def new_root(filepath, root):
|
def new_root(filepath, root):
|
||||||
|
|
Loading…
Reference in a new issue