fix: replace distutils.strtobool() with locally implemented version per PEP 632

This commit is contained in:
Stephen Sadowski 2022-01-23 09:43:14 -06:00
parent 88ca56dda3
commit ca3bea3425

View File

@ -1,12 +1,25 @@
import asyncio
from distutils.util import strtobool
from os import getenv
from sanic.compat import OS_IS_WINDOWS
from sanic.log import error_logger
def strtobool(query: str) -> bool:
"""
reimplement strtobool per PEP 632 and python 3.12 deprecation
True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. Raises ValueError if val is anything else.
"""
if query.lower() in ["y", "yes", "t", "true", "on", "1"]:
return True
elif query.lower() in ["n", "no", "f", "false", "off", "0"]:
return False
else:
raise ValueError
def try_use_uvloop() -> None:
"""
Use uvloop instead of the default asyncio loop.