mini-aiohttp 0.1.1__tar.gz → 0.1.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.
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/PKG-INFO +2 -2
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp/__init__.py +1 -1
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp/server.py +11 -10
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp.egg-info/PKG-INFO +2 -2
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/pyproject.toml +5 -3
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/LICENSE +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/README.md +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp/batch.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp/client.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp/response.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp.egg-info/SOURCES.txt +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp.egg-info/dependency_links.txt +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp.egg-info/requires.txt +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/mini_aiohttp.egg-info/top_level.txt +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/setup.cfg +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/tests/test_batch.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/tests/test_client.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/tests/test_routing.py +0 -0
- {mini_aiohttp-0.1.1 → mini_aiohttp-0.1.2}/tests/test_server.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mini-aiohttp
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A small, dependency-free async HTTP/1.1 client and server built on asyncio
|
|
5
|
-
License: MIT
|
|
5
|
+
License-Expression: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
@@ -29,6 +29,10 @@ def _split_path(path: str) -> list:
|
|
|
29
29
|
return [seg for seg in path.split("/") if seg]
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def _param_count(pattern: list) -> int:
|
|
33
|
+
return sum(1 for seg in pattern if seg.startswith("{") and seg.endswith("}"))
|
|
34
|
+
|
|
35
|
+
|
|
32
36
|
def _match_pattern(pattern: list, segments: list):
|
|
33
37
|
"""Return a dict of captured params if the path matches the pattern, else None."""
|
|
34
38
|
if len(pattern) != len(segments):
|
|
@@ -81,11 +85,14 @@ class Server:
|
|
|
81
85
|
"""Register a handler. Use {name} in the path to capture a segment: '/users/{id}'."""
|
|
82
86
|
def decorator(handler):
|
|
83
87
|
self.routes.append((method.upper(), _split_path(path), handler))
|
|
88
|
+
# Routes with fewer {params} are tried first, so '/users/me' beats '/users/{id}'
|
|
89
|
+
# no matter which one was registered first. sort() is stable, so ties keep order.
|
|
90
|
+
self.routes.sort(key=lambda r: _param_count(r[1]))
|
|
84
91
|
return handler
|
|
85
92
|
return decorator
|
|
86
93
|
|
|
87
94
|
def middleware_(self, fn):
|
|
88
|
-
"""Register middleware. It runs for every
|
|
95
|
+
"""Register middleware. It runs for every routed request, in the order added.
|
|
89
96
|
|
|
90
97
|
@app.middleware_
|
|
91
98
|
async def log(req, call_next):
|
|
@@ -96,22 +103,16 @@ class Server:
|
|
|
96
103
|
return fn
|
|
97
104
|
|
|
98
105
|
def _match(self, method: str, path: str):
|
|
99
|
-
"""Pick the most specific route: fewest path params wins, so /users/me beats /users/{id}."""
|
|
100
106
|
segments = _split_path(path)
|
|
101
107
|
path_seen = False
|
|
102
|
-
best = None # (param_count, handler, params)
|
|
103
108
|
for route_method, pattern, handler in self.routes:
|
|
104
109
|
params = _match_pattern(pattern, segments)
|
|
105
110
|
if params is None:
|
|
106
111
|
continue
|
|
107
112
|
path_seen = True
|
|
108
|
-
if route_method
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
best = (len(params), handler, params)
|
|
112
|
-
if best is None:
|
|
113
|
-
return None, None, path_seen
|
|
114
|
-
return best[1], best[2], True
|
|
113
|
+
if route_method == method:
|
|
114
|
+
return handler, params, True
|
|
115
|
+
return None, None, path_seen
|
|
115
116
|
|
|
116
117
|
async def _dispatch(self, req: Request) -> Response:
|
|
117
118
|
handler, params, path_seen = self._match(req.method, req.path)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mini-aiohttp
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A small, dependency-free async HTTP/1.1 client and server built on asyncio
|
|
5
|
-
License: MIT
|
|
5
|
+
License-Expression: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mini-aiohttp"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "A small, dependency-free async HTTP/1.1 client and server built on asyncio"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
license =
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
11
12
|
requires-python = ">=3.9"
|
|
12
13
|
dependencies = []
|
|
13
14
|
|
|
@@ -19,4 +20,5 @@ include = ["mini_aiohttp*"]
|
|
|
19
20
|
|
|
20
21
|
[tool.pytest.ini_options]
|
|
21
22
|
asyncio_mode = "auto"
|
|
23
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
22
24
|
testpaths = ["tests"]
|
|
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
|