uvicorn 0.32.0__py3-none-any.whl → 0.33.0__py3-none-any.whl

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/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from uvicorn.config import Config
2
2
  from uvicorn.main import Server, main, run
3
3
 
4
- __version__ = "0.32.0"
4
+ __version__ = "0.33.0"
5
5
  __all__ = ["main", "run", "Config", "Server"]
uvicorn/config.py CHANGED
@@ -137,7 +137,7 @@ def resolve_reload_patterns(patterns_list: list[str], directories_list: list[str
137
137
  # Special case for the .* pattern, otherwise this would only match
138
138
  # hidden directories which is probably undesired
139
139
  if pattern == ".*":
140
- continue
140
+ continue # pragma: py-darwin
141
141
  patterns.append(pattern)
142
142
  if is_dir(Path(pattern)):
143
143
  directories.append(Path(pattern))
uvicorn/logging.py CHANGED
@@ -16,7 +16,7 @@ class ColourizedFormatter(logging.Formatter):
16
16
  A custom log formatter class that:
17
17
 
18
18
  * Outputs the LOG_LEVEL with an appropriate color.
19
- * If a log call includes an `extras={"color_message": ...}` it will be used
19
+ * If a log call includes an `extra={"color_message": ...}` it will be used
20
20
  for formatting the output, instead of the plain text message.
21
21
  """
22
22
 
@@ -200,10 +200,7 @@ class H11Protocol(asyncio.Protocol):
200
200
  full_raw_path = self.root_path.encode("ascii") + raw_path
201
201
  self.scope = {
202
202
  "type": "http",
203
- "asgi": {
204
- "version": self.config.asgi_version,
205
- "spec_version": "2.4",
206
- },
203
+ "asgi": {"version": self.config.asgi_version, "spec_version": "2.3"},
207
204
  "http_version": event.http_version.decode("ascii"),
208
205
  "server": self.server,
209
206
  "client": self.client,
@@ -58,6 +58,14 @@ class HttpToolsProtocol(asyncio.Protocol):
58
58
  self.access_logger = logging.getLogger("uvicorn.access")
59
59
  self.access_log = self.access_logger.hasHandlers()
60
60
  self.parser = httptools.HttpRequestParser(self)
61
+
62
+ try:
63
+ # Enable dangerous leniencies to allow server to a response on the first request from a pipelined request.
64
+ self.parser.set_dangerous_leniencies(lenient_data_after_close=True)
65
+ except AttributeError: # pragma: no cover
66
+ # httptools < 0.6.3
67
+ pass
68
+
61
69
  self.ws_protocol_class = config.ws_protocol_class
62
70
  self.root_path = config.root_path
63
71
  self.limit_concurrency = config.limit_concurrency
@@ -214,7 +222,7 @@ class HttpToolsProtocol(asyncio.Protocol):
214
222
  self.headers = []
215
223
  self.scope = { # type: ignore[typeddict-item]
216
224
  "type": "http",
217
- "asgi": {"version": self.config.asgi_version, "spec_version": "2.4"},
225
+ "asgi": {"version": self.config.asgi_version, "spec_version": "2.3"},
218
226
  "http_version": "1.1",
219
227
  "server": self.server,
220
228
  "client": self.client,
@@ -9,15 +9,8 @@ if TYPE_CHECKING:
9
9
  ChangeReload: type[BaseReload]
10
10
  else:
11
11
  try:
12
- from uvicorn.supervisors.watchfilesreload import (
13
- WatchFilesReload as ChangeReload,
14
- )
12
+ from uvicorn.supervisors.watchfilesreload import WatchFilesReload as ChangeReload
15
13
  except ImportError: # pragma: no cover
16
- try:
17
- from uvicorn.supervisors.watchgodreload import (
18
- WatchGodReload as ChangeReload,
19
- )
20
- except ImportError:
21
- from uvicorn.supervisors.statreload import StatReload as ChangeReload
14
+ from uvicorn.supervisors.statreload import StatReload as ChangeReload
22
15
 
23
16
  __all__ = ["Multiprocess", "ChangeReload"]
uvicorn/workers.py CHANGED
@@ -11,7 +11,7 @@ from gunicorn.arbiter import Arbiter
11
11
  from gunicorn.workers.base import Worker
12
12
 
13
13
  from uvicorn.config import Config
14
- from uvicorn.main import Server
14
+ from uvicorn.server import Server
15
15
 
16
16
  warnings.warn(
17
17
  "The `uvicorn.workers` module is deprecated. Please use `uvicorn-worker` package instead.\n"
@@ -1,14 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: uvicorn
3
- Version: 0.32.0
3
+ Version: 0.33.0
4
4
  Summary: The lightning-fast ASGI server.
5
5
  Project-URL: Changelog, https://github.com/encode/uvicorn/blob/master/CHANGELOG.md
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-Expression: BSD-3-Clause
11
- License-File: LICENSE.md
10
+ License: BSD-3-Clause
12
11
  Classifier: Development Status :: 4 - Beta
13
12
  Classifier: Environment :: Web Environment
14
13
  Classifier: Intended Audience :: Developers
@@ -30,7 +29,7 @@ Requires-Dist: h11>=0.8
30
29
  Requires-Dist: typing-extensions>=4.0; python_version < '3.11'
31
30
  Provides-Extra: standard
32
31
  Requires-Dist: colorama>=0.4; (sys_platform == 'win32') and extra == 'standard'
33
- Requires-Dist: httptools>=0.5.0; extra == 'standard'
32
+ Requires-Dist: httptools>=0.6.3; extra == 'standard'
34
33
  Requires-Dist: python-dotenv>=0.13; extra == 'standard'
35
34
  Requires-Dist: pyyaml>=5.1; extra == 'standard'
36
35
  Requires-Dist: uvloop!=0.15.0,!=0.15.1,>=0.14.0; (sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')) and extra == 'standard'
@@ -1,14 +1,14 @@
1
- uvicorn/__init__.py,sha256=WepnRLFNoKFn9CYP5C2Ya8jtfACAx_r-T_E5yIIQU6Q,147
1
+ uvicorn/__init__.py,sha256=nQrfD4JNBDymcrFz6K1qe5h9zmUYcCjhNChn_ySwPPs,147
2
2
  uvicorn/__main__.py,sha256=DQizy6nKP0ywhPpnCHgmRDYIMfcqZKVEzNIWQZjqtVQ,62
3
3
  uvicorn/_subprocess.py,sha256=HbfRnsCkXyg7xCWVAWWzXQTeWlvLKfTlIF5wevFBkR4,2766
4
4
  uvicorn/_types.py,sha256=TcUzCyKNq90ZX2Hxa6ce0juF558zLO_AyBB1XijnD2Y,7814
5
- uvicorn/config.py,sha256=gpsukzuJFbXBRN5_qOnLGiENmGgKM0Fi-eZJ6GwM1dQ,20849
5
+ uvicorn/config.py,sha256=GxC0lBCK0rLFJsloj_yqqS0NZ9QoBN89525b0V_yws4,20870
6
6
  uvicorn/importer.py,sha256=nRt0QQ3qpi264-n_mR0l55C2ddM8nowTNzT1jsWaam8,1128
7
- uvicorn/logging.py,sha256=sg4D9lHaW_kKQj_kmP-bolbChjKfhBuihktlWp8RjSI,4236
7
+ uvicorn/logging.py,sha256=-eCE4nOJmFbtB9qfNJuEVNF0Y13LGUHqvFzemYT0PaQ,4235
8
8
  uvicorn/main.py,sha256=iv6ptgDBnko0W-VkHs0e3I4UrF7_5sEZrntQNKJGFNY,16915
9
9
  uvicorn/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
10
10
  uvicorn/server.py,sha256=McDmVn0sBIVOzaCoKrp10oxaScD3tosoWhtsL1YldNo,13010
11
- uvicorn/workers.py,sha256=DukTKlrCyyvWVHbJWBJflIV2yUe-q6KaGdrEwLrNmyc,3893
11
+ uvicorn/workers.py,sha256=7KGgGAapxGkGeXUcBGunOjSNdI9R44KCoWTGEAqAdfs,3895
12
12
  uvicorn/lifespan/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  uvicorn/lifespan/off.py,sha256=nfI6qHAUo_8-BEXMBKoHQ9wUbsXrPaXLCbDSS0vKSr8,332
14
14
  uvicorn/lifespan/on.py,sha256=1KYuFNNyQONIjtEHhKZAJp-OOokIyjj74wpGCGBv4lk,5184
@@ -26,20 +26,19 @@ uvicorn/protocols/utils.py,sha256=rCjYLd4_uwPeZkbRXQ6beCfxyI_oYpvJCwz3jEGNOiE,18
26
26
  uvicorn/protocols/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  uvicorn/protocols/http/auto.py,sha256=YfXGyzWTaaE2p_jkTPWrJCXsxEaQnC3NK0-G7Wgmnls,403
28
28
  uvicorn/protocols/http/flow_control.py,sha256=050WVg31EvPOkHwynCoMP1zXFl_vO3U4durlc5vyp4U,1701
29
- uvicorn/protocols/http/h11_impl.py,sha256=MuX72-pIyZGHDtZ75-1mveeTj6_ruL-306Ug7z0yV8w,20765
30
- uvicorn/protocols/http/httptools_impl.py,sha256=TikbbIZRFG08KTClZER47ehM1Tu8koBfT6WGU5t5ACg,21491
29
+ uvicorn/protocols/http/h11_impl.py,sha256=4b-KswK57FBaRPeHXlK_oy8pKM6vG1haALCIeRH-1bA,20694
30
+ uvicorn/protocols/http/httptools_impl.py,sha256=tuQBCiD6rf5DQeyQwHVc45rxH9ouojMpkXi9KG6NRBk,21805
31
31
  uvicorn/protocols/websockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  uvicorn/protocols/websockets/auto.py,sha256=kNP-h07ZzjA9dKRUd7MNO0J7xhRJ5xVBfit7wCbdB0A,574
33
33
  uvicorn/protocols/websockets/websockets_impl.py,sha256=LV58OW3whQAd4iwbJl4R3iIod8myVYK3IhAn6F5VeZ4,15490
34
34
  uvicorn/protocols/websockets/wsproto_impl.py,sha256=haJEXK82Ldu8_hz4NDxQ0KpPXa9vOi6pG6iDLoBDKjs,15341
35
- uvicorn/supervisors/__init__.py,sha256=UVJYW3RVHMDSgUytToyAgGyd9NUQVqbNpVrQrvm4Tpc,700
35
+ uvicorn/supervisors/__init__.py,sha256=wT8eOEIqT1yWQgytZtv5taWMul7xoTIY0xm1m4oyPTw,507
36
36
  uvicorn/supervisors/basereload.py,sha256=Hxezjgt_HXkOPVj-hJGH7uj0bZ3EhmwsmaOBc63ySoM,3831
37
37
  uvicorn/supervisors/multiprocess.py,sha256=Opt0XvOUj1DIMXYwb4OlkJZxeh_RjweFnTmDPYItONw,7507
38
38
  uvicorn/supervisors/statreload.py,sha256=gc-HUB44f811PvxD_ZIEQYenM7mWmhQQjYg7KKQ1c5o,1542
39
39
  uvicorn/supervisors/watchfilesreload.py,sha256=41FGNMXPKrKvPr-5O8yRWg43l6OCBtapt39M-gpdk0E,3010
40
- uvicorn/supervisors/watchgodreload.py,sha256=kd-gOvp14ArTNIc206Nt5CEjZZ4NP2UmMVYE7571yRQ,5486
41
- uvicorn-0.32.0.dist-info/METADATA,sha256=uM66dN5rYhRB3gOPuEfEVITkmMNPGXNNX5V5b2mkgXw,6620
42
- uvicorn-0.32.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
43
- uvicorn-0.32.0.dist-info/entry_points.txt,sha256=FW1w-hkc9QgwaGoovMvm0ZY73w_NcycWdGAUfDsNGxw,46
44
- uvicorn-0.32.0.dist-info/licenses/LICENSE.md,sha256=7-Gs8-YvuZwoiw7HPlp3O3Jo70Mg_nV-qZQhTktjw3E,1526
45
- uvicorn-0.32.0.dist-info/RECORD,,
40
+ uvicorn-0.33.0.dist-info/METADATA,sha256=qpnMGZS9iuwL1XUUHOvHeSAhzTL-aDsrko1-xB809pM,6584
41
+ uvicorn-0.33.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
42
+ uvicorn-0.33.0.dist-info/entry_points.txt,sha256=FW1w-hkc9QgwaGoovMvm0ZY73w_NcycWdGAUfDsNGxw,46
43
+ uvicorn-0.33.0.dist-info/licenses/LICENSE.md,sha256=7-Gs8-YvuZwoiw7HPlp3O3Jo70Mg_nV-qZQhTktjw3E,1526
44
+ uvicorn-0.33.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.25.0
2
+ Generator: hatchling 1.26.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,152 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import logging
4
- import warnings
5
- from pathlib import Path
6
- from socket import socket
7
- from typing import TYPE_CHECKING, Callable
8
-
9
- from watchgod import DefaultWatcher
10
-
11
- from uvicorn.config import Config
12
- from uvicorn.supervisors.basereload import BaseReload
13
-
14
- if TYPE_CHECKING:
15
- import os
16
-
17
- DirEntry = os.DirEntry[str]
18
-
19
- logger = logging.getLogger("uvicorn.error")
20
-
21
-
22
- class CustomWatcher(DefaultWatcher):
23
- def __init__(self, root_path: Path, config: Config):
24
- default_includes = ["*.py"]
25
- self.includes = [default for default in default_includes if default not in config.reload_excludes]
26
- self.includes.extend(config.reload_includes)
27
- self.includes = list(set(self.includes))
28
-
29
- default_excludes = [".*", ".py[cod]", ".sw.*", "~*"]
30
- self.excludes = [default for default in default_excludes if default not in config.reload_includes]
31
- self.excludes.extend(config.reload_excludes)
32
- self.excludes = list(set(self.excludes))
33
-
34
- self.watched_dirs: dict[str, bool] = {}
35
- self.watched_files: dict[str, bool] = {}
36
- self.dirs_includes = set(config.reload_dirs)
37
- self.dirs_excludes = set(config.reload_dirs_excludes)
38
- self.resolved_root = root_path
39
- super().__init__(str(root_path))
40
-
41
- def should_watch_file(self, entry: DirEntry) -> bool:
42
- cached_result = self.watched_files.get(entry.path)
43
- if cached_result is not None:
44
- return cached_result
45
-
46
- entry_path = Path(entry)
47
-
48
- # cwd is not verified through should_watch_dir, so we need to verify here
49
- if entry_path.parent == Path.cwd() and Path.cwd() not in self.dirs_includes:
50
- self.watched_files[entry.path] = False
51
- return False
52
- for include_pattern in self.includes:
53
- if str(entry_path).endswith(include_pattern):
54
- self.watched_files[entry.path] = True
55
- return True
56
- if entry_path.match(include_pattern):
57
- for exclude_pattern in self.excludes:
58
- if entry_path.match(exclude_pattern):
59
- self.watched_files[entry.path] = False
60
- return False
61
- self.watched_files[entry.path] = True
62
- return True
63
- self.watched_files[entry.path] = False
64
- return False
65
-
66
- def should_watch_dir(self, entry: DirEntry) -> bool:
67
- cached_result = self.watched_dirs.get(entry.path)
68
- if cached_result is not None:
69
- return cached_result
70
-
71
- entry_path = Path(entry)
72
-
73
- if entry_path in self.dirs_excludes:
74
- self.watched_dirs[entry.path] = False
75
- return False
76
-
77
- for exclude_pattern in self.excludes:
78
- if entry_path.match(exclude_pattern):
79
- is_watched = False
80
- if entry_path in self.dirs_includes:
81
- is_watched = True
82
-
83
- for directory in self.dirs_includes:
84
- if directory in entry_path.parents:
85
- is_watched = True
86
-
87
- if is_watched:
88
- logger.debug(
89
- "WatchGodReload detected a new excluded dir '%s' in '%s'; " "Adding to exclude list.",
90
- entry_path.relative_to(self.resolved_root),
91
- str(self.resolved_root),
92
- )
93
- self.watched_dirs[entry.path] = False
94
- self.dirs_excludes.add(entry_path)
95
- return False
96
-
97
- if entry_path in self.dirs_includes:
98
- self.watched_dirs[entry.path] = True
99
- return True
100
-
101
- for directory in self.dirs_includes:
102
- if directory in entry_path.parents:
103
- self.watched_dirs[entry.path] = True
104
- return True
105
-
106
- for include_pattern in self.includes:
107
- if entry_path.match(include_pattern):
108
- logger.info(
109
- "WatchGodReload detected a new reload dir '%s' in '%s'; " "Adding to watch list.",
110
- str(entry_path.relative_to(self.resolved_root)),
111
- str(self.resolved_root),
112
- )
113
- self.dirs_includes.add(entry_path)
114
- self.watched_dirs[entry.path] = True
115
- return True
116
-
117
- self.watched_dirs[entry.path] = False
118
- return False
119
-
120
-
121
- class WatchGodReload(BaseReload):
122
- def __init__(
123
- self,
124
- config: Config,
125
- target: Callable[[list[socket] | None], None],
126
- sockets: list[socket],
127
- ) -> None:
128
- warnings.warn(
129
- '"watchgod" is deprecated, you should switch ' "to watchfiles (`pip install watchfiles`).",
130
- DeprecationWarning,
131
- )
132
- super().__init__(config, target, sockets)
133
- self.reloader_name = "WatchGod"
134
- self.watchers = []
135
- reload_dirs = []
136
- for directory in config.reload_dirs:
137
- if Path.cwd() not in directory.parents:
138
- reload_dirs.append(directory)
139
- if Path.cwd() not in reload_dirs:
140
- reload_dirs.append(Path.cwd())
141
- for w in reload_dirs:
142
- self.watchers.append(CustomWatcher(w.resolve(), self.config))
143
-
144
- def should_restart(self) -> list[Path] | None:
145
- self.pause()
146
-
147
- for watcher in self.watchers:
148
- change = watcher.check()
149
- if change != set():
150
- return list({Path(c[1]) for c in change})
151
-
152
- return None