Compare commits
10 Commits
main
...
fix-2388-s
Author | SHA1 | Date | |
---|---|---|---|
|
0a84b6cfdb | ||
|
2750f0f82a | ||
|
0f5de2ef2c | ||
|
aef131af90 | ||
|
6e40292974 | ||
|
db92c1fedd | ||
|
bbffdcbd68 | ||
|
768d0e09b5 | ||
|
9d04f24298 | ||
|
6f18c82879 |
|
@ -6,5 +6,5 @@ data = ""
|
||||||
for i in range(1, 250000):
|
for i in range(1, 250000):
|
||||||
data += str(i)
|
data += str(i)
|
||||||
|
|
||||||
r = requests.post('http://0.0.0.0:8000/stream', data=data)
|
r = requests.post("http://0.0.0.0:8000/stream", data=data)
|
||||||
print(r.text)
|
print(r.text)
|
||||||
|
|
|
@ -1,12 +1,26 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from distutils.util import strtobool
|
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
|
||||||
from sanic.compat import OS_IS_WINDOWS
|
from sanic.compat import OS_IS_WINDOWS
|
||||||
from sanic.log import error_logger
|
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(f"String value {query} cannot be converted to bool")
|
||||||
|
|
||||||
|
|
||||||
def try_use_uvloop() -> None:
|
def try_use_uvloop() -> None:
|
||||||
"""
|
"""
|
||||||
Use uvloop instead of the default asyncio loop.
|
Use uvloop instead of the default asyncio loop.
|
||||||
|
|
|
@ -11,35 +11,18 @@ from sanic.helpers import import_string
|
||||||
|
|
||||||
|
|
||||||
def str_to_bool(val: str) -> bool:
|
def str_to_bool(val: str) -> bool:
|
||||||
"""Takes string and tries to turn it into bool as human would do.
|
"""
|
||||||
|
reimplement strtobool per PEP 632 and python 3.12 deprecation
|
||||||
|
|
||||||
If val is in case insensitive (
|
True values are y, yes, t, true, on and 1; false values are n, no, f,
|
||||||
"y", "yes", "yep", "yup", "t",
|
false, off and 0. Raises ValueError if val is anything else.
|
||||||
"true", "on", "enable", "enabled", "1"
|
"""
|
||||||
) returns True.
|
if val.lower() in ["y", "yes", "t", "true", "on", "1"]:
|
||||||
If val is in case insensitive (
|
|
||||||
"n", "no", "f", "false", "off", "disable", "disabled", "0"
|
|
||||||
) returns False.
|
|
||||||
Else Raise ValueError."""
|
|
||||||
|
|
||||||
val = val.lower()
|
|
||||||
if val in {
|
|
||||||
"y",
|
|
||||||
"yes",
|
|
||||||
"yep",
|
|
||||||
"yup",
|
|
||||||
"t",
|
|
||||||
"true",
|
|
||||||
"on",
|
|
||||||
"enable",
|
|
||||||
"enabled",
|
|
||||||
"1",
|
|
||||||
}:
|
|
||||||
return True
|
return True
|
||||||
elif val in {"n", "no", "f", "false", "off", "disable", "disabled", "0"}:
|
elif val.lower() in ["n", "no", "f", "false", "off", "0"]:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid truth value {val}")
|
raise ValueError(f"String value {val} cannot be converted to bool")
|
||||||
|
|
||||||
|
|
||||||
def load_module_from_file_location(
|
def load_module_from_file_location(
|
||||||
|
|
21
setup.py
21
setup.py
|
@ -6,8 +6,6 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from distutils.util import strtobool
|
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
from setuptools.command.test import test as TestCommand
|
from setuptools.command.test import test as TestCommand
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ setup_kwargs = {
|
||||||
"Build fast. Run fast."
|
"Build fast. Run fast."
|
||||||
),
|
),
|
||||||
"long_description": long_description,
|
"long_description": long_description,
|
||||||
"packages": find_packages(),
|
"packages": find_packages(include=[]),
|
||||||
"package_data": {"sanic": ["py.typed"]},
|
"package_data": {"sanic": ["py.typed"]},
|
||||||
"platforms": "any",
|
"platforms": "any",
|
||||||
"python_requires": ">=3.7",
|
"python_requires": ">=3.7",
|
||||||
|
@ -132,6 +130,23 @@ dev_require = tests_require + [
|
||||||
|
|
||||||
all_require = list(set(dev_require + docs_require))
|
all_require = list(set(dev_require + docs_require))
|
||||||
|
|
||||||
|
# trying to self-refernce this from within sanic prior to install is
|
||||||
|
# problematic
|
||||||
|
def strtobool(val: 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 val.lower() in ["y", "yes", "t", "true", "on", "1"]:
|
||||||
|
return True
|
||||||
|
elif val.lower() in ["n", "no", "f", "false", "off", "0"]:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
raise ValueError(f"String value {val} cannot be converted to bool")
|
||||||
|
|
||||||
|
|
||||||
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
|
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
|
||||||
print("Installing without uJSON")
|
print("Installing without uJSON")
|
||||||
requirements.remove(ujson)
|
requirements.remove(ujson)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import pytest
|
||||||
|
|
||||||
from sanic.exceptions import LoadFileException
|
from sanic.exceptions import LoadFileException
|
||||||
from sanic.utils import load_module_from_file_location
|
from sanic.utils import load_module_from_file_location
|
||||||
|
from sanic.utils import str_to_bool as strtobool
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -48,3 +49,20 @@ def test_load_module_from_file_location_using_env():
|
||||||
module = load_module_from_file_location(location)
|
module = load_module_from_file_location(location)
|
||||||
|
|
||||||
assert isinstance(module, ModuleType)
|
assert isinstance(module, ModuleType)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"valid,values",
|
||||||
|
(
|
||||||
|
(True, ["y", "yes", "t", "true", "on", "1", "Y", "yEs", "True"]),
|
||||||
|
(False, ["n", "no", "f", "false", "off", "0", "N", "No", "False"]),
|
||||||
|
(None, ["yyy", "foo"]),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_strtobool(valid, values):
|
||||||
|
for value in values:
|
||||||
|
if valid is None:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
strtobool(value)
|
||||||
|
else:
|
||||||
|
assert strtobool(value) is valid
|
||||||
|
|
Loading…
Reference in New Issue
Block a user