From 6f18c828791a733bc9f5a9a04e6f8184c4f073b0 Mon Sep 17 00:00:00 2001 From: Stephen Sadowski Date: Sun, 23 Jan 2022 09:43:14 -0600 Subject: [PATCH] fix: replace distutils.strtobool() with locally implemented version per PEP 632 --- sanic/server/loop.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sanic/server/loop.py b/sanic/server/loop.py index 5613f709..72b6f063 100644 --- a/sanic/server/loop.py +++ b/sanic/server/loop.py @@ -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.