uvicorn 0.34.0__tar.gz → 0.34.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {uvicorn-0.34.0 → uvicorn-0.34.2}/.gitignore +1 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/PKG-INFO +5 -4
- {uvicorn-0.34.0 → uvicorn-0.34.2}/pyproject.toml +4 -2
- {uvicorn-0.34.0 → uvicorn-0.34.2}/requirements.txt +12 -10
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/protocols/test_http.py +2 -2
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/protocols/test_websocket.py +10 -14
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/supervisors/test_reload.py +23 -19
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_auto_detection.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_cli.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_config.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_main.py +12 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_server.py +4 -2
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/__init__.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/config.py +3 -3
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/main.py +19 -6
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/middleware/wsgi.py +1 -2
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/websockets/websockets_impl.py +4 -4
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/websockets/wsproto_impl.py +2 -2
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/server.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/supervisors/basereload.py +4 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/supervisors/statreload.py +1 -1
- {uvicorn-0.34.0 → uvicorn-0.34.2}/LICENSE.md +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/README.md +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/conftest.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/importer/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/importer/circular_import_a.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/importer/circular_import_b.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/importer/raise_import_error.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/importer/test_importer.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/middleware/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/middleware/test_logging.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/middleware/test_message_logger.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/middleware/test_proxy_headers.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/middleware/test_wsgi.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/protocols/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/protocols/test_utils.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/response.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/supervisors/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/supervisors/test_multiprocess.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/supervisors/test_signal.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_default_headers.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_lifespan.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_ssl.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/test_subprocess.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/tests/utils.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/__main__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/_subprocess.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/_types.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/importer.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/lifespan/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/lifespan/off.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/lifespan/on.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/logging.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/loops/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/loops/asyncio.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/loops/auto.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/loops/uvloop.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/middleware/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/middleware/asgi2.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/middleware/message_logger.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/middleware/proxy_headers.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/http/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/http/auto.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/http/flow_control.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/http/h11_impl.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/http/httptools_impl.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/utils.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/websockets/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/protocols/websockets/auto.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/py.typed +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/supervisors/__init__.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/supervisors/multiprocess.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/supervisors/watchfilesreload.py +0 -0
- {uvicorn-0.34.0 → uvicorn-0.34.2}/uvicorn/workers.py +0 -0
@@ -1,13 +1,14 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: uvicorn
|
3
|
-
Version: 0.34.
|
3
|
+
Version: 0.34.2
|
4
4
|
Summary: The lightning-fast ASGI server.
|
5
|
-
Project-URL: Changelog, https://
|
5
|
+
Project-URL: Changelog, https://www.uvicorn.org/release-notes
|
6
6
|
Project-URL: Funding, https://github.com/sponsors/encode
|
7
7
|
Project-URL: Homepage, https://www.uvicorn.org/
|
8
8
|
Project-URL: Source, https://github.com/encode/uvicorn
|
9
9
|
Author-email: Tom Christie <tom@tomchristie.com>, Marcelo Trylesinski <marcelotryle@gmail.com>
|
10
|
-
License: BSD-3-Clause
|
10
|
+
License-Expression: BSD-3-Clause
|
11
|
+
License-File: LICENSE.md
|
11
12
|
Classifier: Development Status :: 4 - Beta
|
12
13
|
Classifier: Environment :: Web Environment
|
13
14
|
Classifier: Intended Audience :: Developers
|
@@ -50,7 +50,7 @@ standard = [
|
|
50
50
|
uvicorn = "uvicorn.main:main"
|
51
51
|
|
52
52
|
[project.urls]
|
53
|
-
Changelog = "https://
|
53
|
+
Changelog = "https://www.uvicorn.org/release-notes"
|
54
54
|
Funding = "https://github.com/sponsors/encode"
|
55
55
|
Homepage = "https://www.uvicorn.org/"
|
56
56
|
Source = "https://github.com/encode/uvicorn"
|
@@ -85,7 +85,7 @@ disallow_untyped_defs = false
|
|
85
85
|
check_untyped_defs = true
|
86
86
|
|
87
87
|
[tool.pytest.ini_options]
|
88
|
-
addopts = "-rxXs --strict-config --strict-markers"
|
88
|
+
addopts = "-rxXs --strict-config --strict-markers -n 8"
|
89
89
|
xfail_strict = true
|
90
90
|
filterwarnings = [
|
91
91
|
"error",
|
@@ -95,6 +95,7 @@ filterwarnings = [
|
|
95
95
|
]
|
96
96
|
|
97
97
|
[tool.coverage.run]
|
98
|
+
parallel = true
|
98
99
|
source_pkgs = ["uvicorn", "tests"]
|
99
100
|
plugins = ["coverage_conditional_plugin"]
|
100
101
|
omit = ["uvicorn/workers.py", "uvicorn/__main__.py"]
|
@@ -125,6 +126,7 @@ exclude_lines = [
|
|
125
126
|
py-win32 = "sys_platform == 'win32'"
|
126
127
|
py-not-win32 = "sys_platform != 'win32'"
|
127
128
|
py-linux = "sys_platform == 'linux'"
|
129
|
+
py-not-linux = "sys_platform != 'linux'"
|
128
130
|
py-darwin = "sys_platform == 'darwin'"
|
129
131
|
py-gte-39 = "sys_version_info >= (3, 9)"
|
130
132
|
py-lt-39 = "sys_version_info < (3, 9)"
|
@@ -5,27 +5,29 @@
|
|
5
5
|
h11 @ git+https://github.com/python-hyper/h11.git@master
|
6
6
|
|
7
7
|
# Explicit optionals
|
8
|
-
a2wsgi==1.10.
|
8
|
+
a2wsgi==1.10.8
|
9
9
|
wsproto==1.2.0
|
10
10
|
websockets==13.1
|
11
11
|
|
12
12
|
# Packaging
|
13
13
|
build==1.2.2.post1
|
14
|
-
twine==6.0
|
14
|
+
twine==6.1.0
|
15
15
|
|
16
16
|
# Testing
|
17
|
-
ruff==0.
|
18
|
-
pytest==8.3.
|
17
|
+
ruff==0.11.2
|
18
|
+
pytest==8.3.5
|
19
19
|
pytest-mock==3.14.0
|
20
|
-
|
20
|
+
pytest-xdist[psutil]==3.6.1
|
21
|
+
mypy==1.15.0
|
21
22
|
types-click==7.1.8
|
22
|
-
types-pyyaml==6.0.12.
|
23
|
-
trustme==1.2.
|
24
|
-
cryptography==44.0.
|
25
|
-
coverage==7.
|
23
|
+
types-pyyaml==6.0.12.20250326
|
24
|
+
trustme==1.2.1
|
25
|
+
cryptography==44.0.2
|
26
|
+
coverage==7.8.0
|
26
27
|
coverage-conditional-plugin==0.9.0
|
28
|
+
coverage-enable-subprocess==1.0
|
27
29
|
httpx==0.28.1
|
28
30
|
|
29
31
|
# Documentation
|
30
32
|
mkdocs==1.6.1
|
31
|
-
mkdocs-material==9.
|
33
|
+
mkdocs-material==9.6.10
|
@@ -14,8 +14,8 @@ from uvicorn._types import ASGIApplication, ASGIReceiveCallable, ASGISendCallabl
|
|
14
14
|
from uvicorn.config import WS_PROTOCOLS, Config
|
15
15
|
from uvicorn.lifespan.off import LifespanOff
|
16
16
|
from uvicorn.lifespan.on import LifespanOn
|
17
|
-
from uvicorn.main import ServerState
|
18
17
|
from uvicorn.protocols.http.h11_impl import H11Protocol
|
18
|
+
from uvicorn.server import ServerState
|
19
19
|
|
20
20
|
try:
|
21
21
|
from uvicorn.protocols.http.httptools_impl import HttpToolsProtocol
|
@@ -914,7 +914,7 @@ def test_fragmentation(unused_tcp_port: int):
|
|
914
914
|
def send_fragmented_req(path: str):
|
915
915
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
916
916
|
sock.connect(("127.0.0.1", unused_tcp_port))
|
917
|
-
d = (f"GET {path} HTTP/1.1\r\
|
917
|
+
d = (f"GET {path} HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n").encode()
|
918
918
|
split = len(path) // 2
|
919
919
|
sock.sendall(d[:split])
|
920
920
|
time.sleep(0.01)
|
@@ -9,7 +9,6 @@ import pytest
|
|
9
9
|
import websockets
|
10
10
|
import websockets.client
|
11
11
|
import websockets.exceptions
|
12
|
-
from typing_extensions import TypedDict
|
13
12
|
from websockets.extensions.permessage_deflate import ClientPerMessageDeflateFactory
|
14
13
|
from websockets.typing import Subprotocol
|
15
14
|
|
@@ -109,17 +108,14 @@ async def test_invalid_upgrade(ws_protocol_cls: WSProtocol, http_protocol_cls: H
|
|
109
108
|
pass # ok, wsproto 0.13
|
110
109
|
else:
|
111
110
|
assert response.status_code == 400
|
112
|
-
assert (
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
"failed to open a websocket connection: missing sec-websocket-key header; 'sec-websocket-key'",
|
121
|
-
]
|
122
|
-
)
|
111
|
+
assert response.text.lower().strip().rstrip(".") in [
|
112
|
+
"missing sec-websocket-key header",
|
113
|
+
"missing sec-websocket-version header", # websockets
|
114
|
+
"missing or empty sec-websocket-key header", # wsproto
|
115
|
+
"failed to open a websocket connection: missing sec-websocket-key header",
|
116
|
+
"failed to open a websocket connection: missing or empty sec-websocket-key header",
|
117
|
+
"failed to open a websocket connection: missing sec-websocket-key header; 'sec-websocket-key'",
|
118
|
+
]
|
123
119
|
|
124
120
|
|
125
121
|
async def test_accept_connection(ws_protocol_cls: WSProtocol, http_protocol_cls: HTTPProtocol, unused_tcp_port: int):
|
@@ -780,7 +776,7 @@ async def test_server_reject_connection(
|
|
780
776
|
assert disconnected_message == {"type": "websocket.disconnect", "code": 1006}
|
781
777
|
|
782
778
|
|
783
|
-
class EmptyDict(TypedDict): ...
|
779
|
+
class EmptyDict(typing.TypedDict): ...
|
784
780
|
|
785
781
|
|
786
782
|
async def test_server_reject_connection_with_response(
|
@@ -1020,7 +1016,7 @@ async def test_server_multiple_websocket_http_response_start_events(
|
|
1020
1016
|
await websocket_session(f"ws://127.0.0.1:{unused_tcp_port}")
|
1021
1017
|
|
1022
1018
|
assert exception_message == (
|
1023
|
-
"Expected ASGI message 'websocket.http.response.body' but got
|
1019
|
+
"Expected ASGI message 'websocket.http.response.body' but got 'websocket.http.response.start'."
|
1024
1020
|
)
|
1025
1021
|
|
1026
1022
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
import platform
|
4
3
|
import signal
|
5
4
|
import socket
|
6
5
|
import sys
|
@@ -24,11 +23,8 @@ except ImportError: # pragma: no cover
|
|
24
23
|
WatchFilesReload = None # type: ignore[misc,assignment]
|
25
24
|
|
26
25
|
|
27
|
-
# TODO: Investigate why this is flaky on MacOS
|
28
|
-
|
29
|
-
sys.platform == "darwin" and platform.processor() == "arm",
|
30
|
-
reason="Flaky on MacOS M1",
|
31
|
-
)
|
26
|
+
# TODO: Investigate why this is flaky on MacOS, and Windows.
|
27
|
+
skip_non_linux = pytest.mark.skipif(sys.platform in ("darwin", "win32"), reason="Flaky on Windows and MacOS")
|
32
28
|
|
33
29
|
|
34
30
|
def run(sockets: list[socket.socket] | None) -> None:
|
@@ -99,7 +95,7 @@ class TestBaseReload:
|
|
99
95
|
reloader = self._setup_reloader(config)
|
100
96
|
reloader.shutdown()
|
101
97
|
|
102
|
-
@pytest.mark.parametrize("reloader_class", [StatReload, WatchFilesReload])
|
98
|
+
@pytest.mark.parametrize("reloader_class", [StatReload, pytest.param(WatchFilesReload, marks=skip_non_linux)])
|
103
99
|
def test_reload_when_python_file_is_changed(self, touch_soon: Callable[[Path], None]):
|
104
100
|
file = self.reload_path / "main.py"
|
105
101
|
|
@@ -141,8 +137,12 @@ class TestBaseReload:
|
|
141
137
|
|
142
138
|
reloader.shutdown()
|
143
139
|
|
144
|
-
@pytest.mark.parametrize(
|
145
|
-
|
140
|
+
@pytest.mark.parametrize(
|
141
|
+
"reloader_class, result", [(StatReload, False), pytest.param(WatchFilesReload, True, marks=skip_non_linux)]
|
142
|
+
)
|
143
|
+
def test_reload_when_pattern_matched_file_is_changed(
|
144
|
+
self, result: bool, touch_soon: Callable[[Path], None]
|
145
|
+
): # pragma: py-not-linux
|
146
146
|
file = self.reload_path / "app" / "js" / "main.js"
|
147
147
|
|
148
148
|
with as_cwd(self.reload_path):
|
@@ -153,10 +153,10 @@ class TestBaseReload:
|
|
153
153
|
|
154
154
|
reloader.shutdown()
|
155
155
|
|
156
|
-
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=
|
156
|
+
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=skip_non_linux)])
|
157
157
|
def test_should_not_reload_when_exclude_pattern_match_file_is_changed(
|
158
158
|
self, touch_soon: Callable[[Path], None]
|
159
|
-
): # pragma: py-
|
159
|
+
): # pragma: py-not-linux
|
160
160
|
python_file = self.reload_path / "app" / "src" / "main.py"
|
161
161
|
css_file = self.reload_path / "app" / "css" / "main.css"
|
162
162
|
js_file = self.reload_path / "app" / "js" / "main.js"
|
@@ -188,8 +188,10 @@ class TestBaseReload:
|
|
188
188
|
|
189
189
|
reloader.shutdown()
|
190
190
|
|
191
|
-
@pytest.mark.parametrize("reloader_class", [StatReload, WatchFilesReload])
|
192
|
-
def test_should_reload_when_directories_have_same_prefix(
|
191
|
+
@pytest.mark.parametrize("reloader_class", [StatReload, pytest.param(WatchFilesReload, marks=skip_non_linux)])
|
192
|
+
def test_should_reload_when_directories_have_same_prefix(
|
193
|
+
self, touch_soon: Callable[[Path], None]
|
194
|
+
): # pragma: py-not-linux
|
193
195
|
app_dir = self.reload_path / "app"
|
194
196
|
app_file = app_dir / "src" / "main.py"
|
195
197
|
app_first_dir = self.reload_path / "app_first"
|
@@ -210,9 +212,11 @@ class TestBaseReload:
|
|
210
212
|
|
211
213
|
@pytest.mark.parametrize(
|
212
214
|
"reloader_class",
|
213
|
-
[StatReload, pytest.param(WatchFilesReload, marks=
|
215
|
+
[StatReload, pytest.param(WatchFilesReload, marks=skip_non_linux)],
|
214
216
|
)
|
215
|
-
def test_should_not_reload_when_only_subdirectory_is_watched(
|
217
|
+
def test_should_not_reload_when_only_subdirectory_is_watched(
|
218
|
+
self, touch_soon: Callable[[Path], None]
|
219
|
+
): # pragma: py-not-linux
|
216
220
|
app_dir = self.reload_path / "app"
|
217
221
|
app_dir_file = self.reload_path / "app" / "src" / "main.py"
|
218
222
|
root_file = self.reload_path / "main.py"
|
@@ -229,8 +233,8 @@ class TestBaseReload:
|
|
229
233
|
|
230
234
|
reloader.shutdown()
|
231
235
|
|
232
|
-
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=
|
233
|
-
def test_override_defaults(self, touch_soon: Callable[[Path], None]) -> None: # pragma: py-
|
236
|
+
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=skip_non_linux)])
|
237
|
+
def test_override_defaults(self, touch_soon: Callable[[Path], None]) -> None: # pragma: py-not-linux
|
234
238
|
dotted_file = self.reload_path / ".dotted"
|
235
239
|
dotted_dir_file = self.reload_path / ".dotted_dir" / "file.txt"
|
236
240
|
python_file = self.reload_path / "main.py"
|
@@ -251,8 +255,8 @@ class TestBaseReload:
|
|
251
255
|
|
252
256
|
reloader.shutdown()
|
253
257
|
|
254
|
-
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=
|
255
|
-
def test_explicit_paths(self, touch_soon: Callable[[Path], None]) -> None: # pragma: py-
|
258
|
+
@pytest.mark.parametrize("reloader_class", [pytest.param(WatchFilesReload, marks=skip_non_linux)])
|
259
|
+
def test_explicit_paths(self, touch_soon: Callable[[Path], None]) -> None: # pragma: py-not-linux
|
256
260
|
dotted_file = self.reload_path / ".dotted"
|
257
261
|
non_dotted_file = self.reload_path / "ext" / "ext.jpg"
|
258
262
|
python_file = self.reload_path / "main.py"
|
@@ -5,9 +5,9 @@ import pytest
|
|
5
5
|
|
6
6
|
from uvicorn.config import Config
|
7
7
|
from uvicorn.loops.auto import auto_loop_setup
|
8
|
-
from uvicorn.main import ServerState
|
9
8
|
from uvicorn.protocols.http.auto import AutoHTTPProtocol
|
10
9
|
from uvicorn.protocols.websockets.auto import AutoWebSocketsProtocol
|
10
|
+
from uvicorn.server import ServerState
|
11
11
|
|
12
12
|
try:
|
13
13
|
importlib.import_module("uvloop")
|
@@ -131,7 +131,7 @@ def test_cli_incomplete_app_parameter() -> None:
|
|
131
131
|
result = runner.invoke(cli, ["tests.test_cli"])
|
132
132
|
|
133
133
|
assert (
|
134
|
-
'Error loading ASGI app. Import string "tests.test_cli"
|
134
|
+
'Error loading ASGI app. Import string "tests.test_cli" must be in format "<module>:<attribute>".'
|
135
135
|
) in result.output
|
136
136
|
assert result.exit_code == 1
|
137
137
|
|
@@ -409,7 +409,7 @@ def test_env_file(
|
|
409
409
|
Test that one can load environment variables using an env file.
|
410
410
|
"""
|
411
411
|
fp = tmp_path / ".env"
|
412
|
-
content = f"WEB_CONCURRENCY={web_concurrency}\
|
412
|
+
content = f"WEB_CONCURRENCY={web_concurrency}\nFORWARDED_ALLOW_IPS={forwarded_allow_ips}\n"
|
413
413
|
fp.write_text(content)
|
414
414
|
with caplog.at_level(logging.INFO):
|
415
415
|
config = Config(app=asgi_app, env_file=fp)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import importlib
|
1
2
|
import inspect
|
2
3
|
import socket
|
3
4
|
from logging import WARNING
|
@@ -5,6 +6,7 @@ from logging import WARNING
|
|
5
6
|
import httpx
|
6
7
|
import pytest
|
7
8
|
|
9
|
+
import uvicorn.server
|
8
10
|
from tests.utils import run_server
|
9
11
|
from uvicorn import Server
|
10
12
|
from uvicorn._types import ASGIReceiveCallable, ASGISendCallable, Scope
|
@@ -79,7 +81,7 @@ def test_run_invalid_app_config_combination(caplog: pytest.LogCaptureFixture) ->
|
|
79
81
|
assert caplog.records[-1].name == "uvicorn.error"
|
80
82
|
assert caplog.records[-1].levelno == WARNING
|
81
83
|
assert caplog.records[-1].message == (
|
82
|
-
"You must pass the application as an import string to enable
|
84
|
+
"You must pass the application as an import string to enable 'reload' or 'workers'."
|
83
85
|
)
|
84
86
|
|
85
87
|
|
@@ -113,3 +115,12 @@ async def test_exit_on_create_server_with_invalid_host() -> None:
|
|
113
115
|
server = Server(config=config)
|
114
116
|
await server.serve()
|
115
117
|
assert exc_info.value.code == 1
|
118
|
+
|
119
|
+
|
120
|
+
def test_deprecated_server_state_from_main() -> None:
|
121
|
+
with pytest.deprecated_call(
|
122
|
+
match="uvicorn.main.ServerState is deprecated, use uvicorn.server.ServerState instead."
|
123
|
+
):
|
124
|
+
main = importlib.import_module("uvicorn.main")
|
125
|
+
server_state_cls = getattr(main, "ServerState")
|
126
|
+
assert server_state_cls is uvicorn.server.ServerState
|
@@ -64,7 +64,9 @@ else: # pragma: py-win32
|
|
64
64
|
@pytest.mark.parametrize("exception_signal", signals)
|
65
65
|
@pytest.mark.parametrize("capture_signal", signal_captures)
|
66
66
|
async def test_server_interrupt(
|
67
|
-
exception_signal: signal.Signals,
|
67
|
+
exception_signal: signal.Signals,
|
68
|
+
capture_signal: Callable[[signal.Signals], AbstractContextManager[None]],
|
69
|
+
unused_tcp_port: int,
|
68
70
|
): # pragma: py-win32
|
69
71
|
"""Test interrupting a Server that is run explicitly inside asyncio"""
|
70
72
|
|
@@ -73,7 +75,7 @@ async def test_server_interrupt(
|
|
73
75
|
await asyncio.sleep(0.01)
|
74
76
|
signal.raise_signal(exception_signal)
|
75
77
|
|
76
|
-
server = Server(Config(app=dummy_app, loop="asyncio"))
|
78
|
+
server = Server(Config(app=dummy_app, loop="asyncio", port=unused_tcp_port))
|
77
79
|
asyncio.create_task(interrupt_running(server))
|
78
80
|
with capture_signal(exception_signal) as witness:
|
79
81
|
await server.serve()
|
@@ -138,7 +138,7 @@ def resolve_reload_patterns(patterns_list: list[str], directories_list: list[str
|
|
138
138
|
# Special case for the .* pattern, otherwise this would only match
|
139
139
|
# hidden directories which is probably undesired
|
140
140
|
if pattern == ".*":
|
141
|
-
continue # pragma: py-
|
141
|
+
continue # pragma: py-not-linux
|
142
142
|
patterns.append(pattern)
|
143
143
|
if is_dir(Path(pattern)):
|
144
144
|
directories.append(Path(pattern))
|
@@ -280,7 +280,7 @@ class Config:
|
|
280
280
|
|
281
281
|
if (reload_dirs or reload_includes or reload_excludes) and not self.should_reload:
|
282
282
|
logger.warning(
|
283
|
-
"Current configuration will not reload as not all conditions are met,
|
283
|
+
"Current configuration will not reload as not all conditions are met, please refer to documentation."
|
284
284
|
)
|
285
285
|
|
286
286
|
if self.should_reload:
|
@@ -446,7 +446,7 @@ class Config:
|
|
446
446
|
else:
|
447
447
|
if not self.factory:
|
448
448
|
logger.warning(
|
449
|
-
"ASGI app factory detected. Using it,
|
449
|
+
"ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly."
|
450
450
|
)
|
451
451
|
|
452
452
|
if self.interface == "auto":
|
@@ -6,6 +6,7 @@ import os
|
|
6
6
|
import platform
|
7
7
|
import ssl
|
8
8
|
import sys
|
9
|
+
import warnings
|
9
10
|
from configparser import RawConfigParser
|
10
11
|
from typing import IO, Any, Callable
|
11
12
|
|
@@ -29,7 +30,7 @@ from uvicorn.config import (
|
|
29
30
|
LoopSetupType,
|
30
31
|
WSProtocolType,
|
31
32
|
)
|
32
|
-
from uvicorn.server import Server
|
33
|
+
from uvicorn.server import Server
|
33
34
|
from uvicorn.supervisors import ChangeReload, Multiprocess
|
34
35
|
|
35
36
|
LEVEL_CHOICES = click.Choice(list(LOG_LEVELS.keys()))
|
@@ -81,7 +82,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
|
|
81
82
|
"--reload-dir",
|
82
83
|
"reload_dirs",
|
83
84
|
multiple=True,
|
84
|
-
help="Set reload directories explicitly, instead of using the current working
|
85
|
+
help="Set reload directories explicitly, instead of using the current working directory.",
|
85
86
|
type=click.Path(exists=True),
|
86
87
|
)
|
87
88
|
@click.option(
|
@@ -106,7 +107,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
|
|
106
107
|
type=float,
|
107
108
|
default=0.25,
|
108
109
|
show_default=True,
|
109
|
-
help="Delay between previous and next check if application needs to be.
|
110
|
+
help="Delay between previous and next check if application needs to be. Defaults to 0.25s.",
|
110
111
|
)
|
111
112
|
@click.option(
|
112
113
|
"--workers",
|
@@ -222,7 +223,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
|
|
222
223
|
"--proxy-headers/--no-proxy-headers",
|
223
224
|
is_flag=True,
|
224
225
|
default=True,
|
225
|
-
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to
|
226
|
+
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info.",
|
226
227
|
)
|
227
228
|
@click.option(
|
228
229
|
"--server-header/--no-server-header",
|
@@ -255,7 +256,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
|
|
255
256
|
"--limit-concurrency",
|
256
257
|
type=int,
|
257
258
|
default=None,
|
258
|
-
help="Maximum number of concurrent connections or tasks to allow, before issuing
|
259
|
+
help="Maximum number of concurrent connections or tasks to allow, before issuing HTTP 503 responses.",
|
259
260
|
)
|
260
261
|
@click.option(
|
261
262
|
"--backlog",
|
@@ -565,7 +566,7 @@ def run(
|
|
565
566
|
|
566
567
|
if (config.reload or config.workers > 1) and not isinstance(app, str):
|
567
568
|
logger = logging.getLogger("uvicorn.error")
|
568
|
-
logger.warning("You must pass the application as an import string to enable 'reload' or
|
569
|
+
logger.warning("You must pass the application as an import string to enable 'reload' or 'workers'.")
|
569
570
|
sys.exit(1)
|
570
571
|
|
571
572
|
try:
|
@@ -587,5 +588,17 @@ def run(
|
|
587
588
|
sys.exit(STARTUP_FAILURE)
|
588
589
|
|
589
590
|
|
591
|
+
def __getattr__(name: str) -> Any:
|
592
|
+
if name == "ServerState":
|
593
|
+
warnings.warn(
|
594
|
+
"uvicorn.main.ServerState is deprecated, use uvicorn.server.ServerState instead.",
|
595
|
+
DeprecationWarning,
|
596
|
+
)
|
597
|
+
from uvicorn.server import ServerState
|
598
|
+
|
599
|
+
return ServerState
|
600
|
+
raise AttributeError(f"module {__name__} has no attribute {name}")
|
601
|
+
|
602
|
+
|
590
603
|
if __name__ == "__main__":
|
591
604
|
main() # pragma: no cover
|
@@ -82,8 +82,7 @@ def build_environ(scope: HTTPScope, message: ASGIReceiveEvent, body: io.BytesIO)
|
|
82
82
|
class _WSGIMiddleware:
|
83
83
|
def __init__(self, app: WSGIApp, workers: int = 10):
|
84
84
|
warnings.warn(
|
85
|
-
"Uvicorn's native WSGI implementation is deprecated, you "
|
86
|
-
"should switch to a2wsgi (`pip install a2wsgi`).",
|
85
|
+
"Uvicorn's native WSGI implementation is deprecated, you should switch to a2wsgi (`pip install a2wsgi`).",
|
87
86
|
DeprecationWarning,
|
88
87
|
)
|
89
88
|
self.app = app
|
@@ -214,7 +214,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|
214
214
|
def send_500_response(self) -> None:
|
215
215
|
msg = b"Internal Server Error"
|
216
216
|
content = [
|
217
|
-
b"HTTP/1.1 500 Internal Server Error\r\
|
217
|
+
b"HTTP/1.1 500 Internal Server Error\r\ncontent-type: text/plain; charset=utf-8\r\n",
|
218
218
|
b"content-length: " + str(len(msg)).encode("ascii") + b"\r\n",
|
219
219
|
b"connection: close\r\n",
|
220
220
|
b"\r\n",
|
@@ -338,7 +338,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|
338
338
|
self.closed_event.set()
|
339
339
|
|
340
340
|
else:
|
341
|
-
msg = "Expected ASGI message 'websocket.send' or 'websocket.close',
|
341
|
+
msg = "Expected ASGI message 'websocket.send' or 'websocket.close', but got '%s'."
|
342
342
|
raise RuntimeError(msg % message_type)
|
343
343
|
except ConnectionClosed as exc:
|
344
344
|
raise ClientDisconnected from exc
|
@@ -351,11 +351,11 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|
351
351
|
if not message.get("more_body", False):
|
352
352
|
self.closed_event.set()
|
353
353
|
else:
|
354
|
-
msg = "Expected ASGI message 'websocket.http.response.body'
|
354
|
+
msg = "Expected ASGI message 'websocket.http.response.body' but got '%s'."
|
355
355
|
raise RuntimeError(msg % message_type)
|
356
356
|
|
357
357
|
else:
|
358
|
-
msg = "Unexpected ASGI message '%s', after sending 'websocket.close'
|
358
|
+
msg = "Unexpected ASGI message '%s', after sending 'websocket.close' or response already completed."
|
359
359
|
raise RuntimeError(msg % message_type)
|
360
360
|
|
361
361
|
async def asgi_receive(self) -> WebSocketDisconnectEvent | WebSocketConnectEvent | WebSocketReceiveEvent:
|
@@ -344,7 +344,7 @@ class WSProtocol(asyncio.Protocol):
|
|
344
344
|
self.transport.close()
|
345
345
|
|
346
346
|
else:
|
347
|
-
msg = "Expected ASGI message 'websocket.send' or 'websocket.close',
|
347
|
+
msg = "Expected ASGI message 'websocket.send' or 'websocket.close', but got '%s'."
|
348
348
|
raise RuntimeError(msg % message_type)
|
349
349
|
except LocalProtocolError as exc:
|
350
350
|
raise ClientDisconnected from exc
|
@@ -362,7 +362,7 @@ class WSProtocol(asyncio.Protocol):
|
|
362
362
|
self.transport.close()
|
363
363
|
|
364
364
|
else:
|
365
|
-
msg = "Expected ASGI message 'websocket.http.response.body'
|
365
|
+
msg = "Expected ASGI message 'websocket.http.response.body' but got '%s'."
|
366
366
|
raise RuntimeError(msg % message_type)
|
367
367
|
|
368
368
|
else:
|
@@ -119,7 +119,7 @@ class Server:
|
|
119
119
|
|
120
120
|
def _share_socket(
|
121
121
|
sock: socket.SocketType,
|
122
|
-
) -> socket.SocketType: # pragma py-
|
122
|
+
) -> socket.SocketType: # pragma py-not-win32
|
123
123
|
# Windows requires the socket be explicitly shared across
|
124
124
|
# multiple workers (processes).
|
125
125
|
from socket import fromshare # type: ignore[attr-defined]
|
@@ -90,6 +90,10 @@ class BaseReload:
|
|
90
90
|
self.is_restarting = True
|
91
91
|
assert self.process.pid is not None
|
92
92
|
os.kill(self.process.pid, signal.CTRL_C_EVENT)
|
93
|
+
|
94
|
+
# This is a workaround to ensure the Ctrl+C event is processed
|
95
|
+
sys.stdout.write(" ") # This has to be a non-empty string
|
96
|
+
sys.stdout.flush()
|
93
97
|
else: # pragma: py-win32
|
94
98
|
self.process.terminate()
|
95
99
|
self.process.join()
|
@@ -24,7 +24,7 @@ class StatReload(BaseReload):
|
|
24
24
|
self.mtimes: dict[Path, float] = {}
|
25
25
|
|
26
26
|
if config.reload_excludes or config.reload_includes:
|
27
|
-
logger.warning("--reload-include and --reload-exclude have no effect unless
|
27
|
+
logger.warning("--reload-include and --reload-exclude have no effect unless watchfiles is installed.")
|
28
28
|
|
29
29
|
def should_restart(self) -> list[Path] | None:
|
30
30
|
self.pause()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|