From bfb7a6cdcc4942048c60d470af64b96e71e84f2e Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 14 Apr 2020 07:50:49 +0200 Subject: [PATCH 1/7] Added AF_UNIX type socket to get client filled --- uvicorn/protocols/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index c9347277d..f9cde61a4 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -14,7 +14,7 @@ def get_remote_addr(transport): else: family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6): + if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("peername") @@ -28,7 +28,7 @@ def get_local_addr(transport): if socket_info is not None: info = socket_info.getsockname() family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6): + if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("sockname") From 2d62aa5b56dee9e47eff633160f89113bdefccf8 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 14 Apr 2020 07:58:54 +0200 Subject: [PATCH 2/7] Removed travis debug --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index bbdd94e0b..49aadd467 100755 --- a/scripts/test +++ b/scripts/test @@ -10,7 +10,7 @@ export PYTHON_VERSION=`${PREFIX}python -c "$VERSION_SCRIPT"` set -x -PYTHONPATH=. ${PREFIX}pytest -s --log-cli-level=debug --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} +PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} ${PREFIX}coverage html ${PREFIX}autoflake --recursive uvicorn tests ${PREFIX}flake8 uvicorn tests --ignore=W503,E203,E501,E731 From 6f7de0cd6a5882f35e64f752aa0a62f37f8862a1 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 14 Apr 2020 09:38:11 +0200 Subject: [PATCH 3/7] Added travis verbose pytest for windows fail check --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index 49aadd467..bbdd94e0b 100755 --- a/scripts/test +++ b/scripts/test @@ -10,7 +10,7 @@ export PYTHON_VERSION=`${PREFIX}python -c "$VERSION_SCRIPT"` set -x -PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} +PYTHONPATH=. ${PREFIX}pytest -s --log-cli-level=debug --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} ${PREFIX}coverage html ${PREFIX}autoflake --recursive uvicorn tests ${PREFIX}flake8 uvicorn tests --ignore=W503,E203,E501,E731 From 455e182b24727dac5c9605c4809181c035271f0f Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 14 Apr 2020 09:58:13 +0200 Subject: [PATCH 4/7] Added travis verbose pytest for windows fail check --- scripts/test | 2 +- uvicorn/protocols/utils.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/test b/scripts/test index bbdd94e0b..023f602cd 100755 --- a/scripts/test +++ b/scripts/test @@ -10,7 +10,7 @@ export PYTHON_VERSION=`${PREFIX}python -c "$VERSION_SCRIPT"` set -x -PYTHONPATH=. ${PREFIX}pytest -s --log-cli-level=debug --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} +PYTHONPATH=. ${PREFIX}pytest -s --log-cli-level=debug --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing "${@}" ${PREFIX}coverage html ${PREFIX}autoflake --recursive uvicorn tests ${PREFIX}flake8 uvicorn tests --ignore=W503,E203,E501,E731 diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index f9cde61a4..44867a4ee 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -1,4 +1,5 @@ import socket +import sys def get_remote_addr(transport): @@ -14,8 +15,12 @@ def get_remote_addr(transport): else: family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): - return (str(info[0]), int(info[1])) + if not sys.platform.startswith("win"): + if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): + return (str(info[0]), int(info[1])) + else: + if family in (socket.AF_INET, socket.AF_INET6): + return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("peername") if info is not None and isinstance(info, (list, tuple)) and len(info) == 2: @@ -28,8 +33,12 @@ def get_local_addr(transport): if socket_info is not None: info = socket_info.getsockname() family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): - return (str(info[0]), int(info[1])) + if not sys.platform.startswith("win"): + if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): + return (str(info[0]), int(info[1])) + else: + if family in (socket.AF_INET, socket.AF_INET6): + return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("sockname") if info is not None and isinstance(info, (list, tuple)) and len(info) == 2: From 8c5646a0f1e902ced43aa7a741fffe4466dc95f5 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 14 Apr 2020 10:01:13 +0200 Subject: [PATCH 5/7] No more tests output in travis now it's fixed on windows --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index 023f602cd..49aadd467 100755 --- a/scripts/test +++ b/scripts/test @@ -10,7 +10,7 @@ export PYTHON_VERSION=`${PREFIX}python -c "$VERSION_SCRIPT"` set -x -PYTHONPATH=. ${PREFIX}pytest -s --log-cli-level=debug --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing "${@}" +PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov=uvicorn --cov=tests --cov-report=term-missing ${@} ${PREFIX}coverage html ${PREFIX}autoflake --recursive uvicorn tests ${PREFIX}flake8 uvicorn tests --ignore=W503,E203,E501,E731 From 5cb106fc4f09ac91497dc1806d03c294c63a69f5 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 19 May 2020 18:30:48 +0200 Subject: [PATCH 6/7] Useing a top level constant --- uvicorn/protocols/utils.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index 44867a4ee..625ad78f9 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -1,6 +1,9 @@ import socket -import sys +if hasattr(socket, 'AF_UNIX'): + SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX) +else: + SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6) def get_remote_addr(transport): socket_info = transport.get_extra_info("socket") @@ -15,12 +18,9 @@ def get_remote_addr(transport): else: family = socket_info.family - if not sys.platform.startswith("win"): - if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): - return (str(info[0]), int(info[1])) - else: - if family in (socket.AF_INET, socket.AF_INET6): - return (str(info[0]), int(info[1])) + if family in SUPPORTED_SOCKET_FAMILIES: + return (str(info[0]), int(info[1])) + return None info = transport.get_extra_info("peername") if info is not None and isinstance(info, (list, tuple)) and len(info) == 2: @@ -33,12 +33,8 @@ def get_local_addr(transport): if socket_info is not None: info = socket_info.getsockname() family = socket_info.family - if not sys.platform.startswith("win"): - if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX): - return (str(info[0]), int(info[1])) - else: - if family in (socket.AF_INET, socket.AF_INET6): - return (str(info[0]), int(info[1])) + if family in SUPPORTED_SOCKET_FAMILIES: + return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("sockname") if info is not None and isinstance(info, (list, tuple)) and len(info) == 2: From 74369eb3b21b4d82ea365fde9017802d93da7fb6 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 19 May 2020 18:36:17 +0200 Subject: [PATCH 7/7] Lint --- uvicorn/protocols/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index 625ad78f9..93422e4bf 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -1,10 +1,11 @@ import socket -if hasattr(socket, 'AF_UNIX'): +if hasattr(socket, "AF_UNIX"): SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX) else: SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6) + def get_remote_addr(transport): socket_info = transport.get_extra_info("socket") if socket_info is not None: