Cleanup manual pipeline construction, pass into breakshaft

This commit is contained in:
2025-07-21 15:52:51 +03:00
parent dd0c896df6
commit 6cb01f6204
3 changed files with 27 additions and 52 deletions

View File

@@ -9,7 +9,7 @@ license = "LGPL-3.0-or-later"
requires-python = ">=3.13"
dependencies = [
"megasniff>=0.2.0",
"breakshaft>=0.1.0",
"breakshaft>=0.1.1",
"case-insensitive-dictionary>=0.2.1",
"mypy>=1.17.0",
]

View File

@@ -231,74 +231,49 @@ class SlothApp(HTTPApp, WSApp, LifespanApp, MethodRoutersApp):
raise ValueError(f'Unable to find request schema in handler {fn}')
query_type, body_type, path_type = get_args(req_schema)
q_inflator = None
b_inflator = None
p_inflator = None
fork_with = set()
def none_generator(*args) -> None:
return None
if path_type not in [PTYPE, None, Any]:
p_inflator = self.infl_generator.schema_to_inflator(
path_type,
strict_mode_override=False,
from_type_override=QTYPE
)
fork_with.add(ConversionPoint(p_inflator, path_type, (PTYPE,)))
else:
fork_with.add(ConversionPoint(none_generator, path_type, (PTYPE,)))
def create_convertor(t, def_type):
infl = None
if t not in [def_type, None, Any]:
infl = self.infl_generator.schema_to_inflator(
t,
strict_mode_override=False,
from_type_override=def_type
)
return ConversionPoint(p_inflator, path_type, (PTYPE,), (), )
else:
return ConversionPoint(none_generator, path_type, (PTYPE,), (), )
if query_type not in [QTYPE, None, Any]:
q_inflator = self.infl_generator.schema_to_inflator(
query_type,
strict_mode_override=False,
from_type_override=QTYPE
)
fork_with.add(ConversionPoint(q_inflator, query_type, (QTYPE,)))
else:
fork_with.add(ConversionPoint(none_generator, query_type, (QTYPE,)))
q_inflator = create_convertor(query_type, QTYPE)
b_inflator = create_convertor(body_type, BTYPE)
p_inflator = create_convertor(path_type, PTYPE)
if body_type != [BTYPE, None, Any]:
b_inflator = self.infl_generator.schema_to_inflator(
body_type,
from_type_override=BTYPE
)
fork_with.add(ConversionPoint(b_inflator, body_type, (BTYPE,)))
else:
fork_with.add(ConversionPoint(none_generator, body_type, (BTYPE,)))
fork_with = {q_inflator, b_inflator, p_inflator}
def construct_unwrap(q, b, p) -> UnwrappedRequest:
def construct_unwrap(q: QTYPE, b: BTYPE, p: PTYPE) -> UnwrappedRequest:
return UnwrappedRequest(q, b, p)
fork_with |= {
ConversionPoint(
construct_unwrap,
req_schema,
((query_type or QTYPE), (body_type or BTYPE), (path_type or PTYPE))
((query_type or QTYPE), (body_type or BTYPE), (path_type or PTYPE)),
(),
)
}
tmp_repo = self.inj_repo.fork(fork_with)
conv = tmp_repo.get_conversion(
(BasicRequest,),
fn,
force_async=True,
)
out_conv = self.inj_repo.get_conversion(
(Send, BasicRequest, handle_hints['return'],),
self.send_answer,
p = tmp_repo.create_pipeline(
(Send, BasicRequest),
[fn, self.send_answer],
force_async=True
)
async def pipeline(send: Send, req: BasicRequest):
ret = await conv(req)
await out_conv(send, req, ret)
self.router.add(method, path_pattern, pipeline)
self.router.add(method, path_pattern, p)
return fn
return decorator

8
uv.lock generated
View File

@@ -4,15 +4,15 @@ requires-python = ">=3.13"
[[package]]
name = "breakshaft"
version = "0.1.0.post2"
version = "0.1.1.post1"
source = { registry = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" }
dependencies = [
{ name = "hatchling" },
{ name = "jinja2" },
]
sdist = { url = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/files/breakshaft/0.1.0.post2/breakshaft-0.1.0.post2.tar.gz", hash = "sha256:d04f8685336080cddb5111422a9624c8afcc8c47264e1b847339139bfd690570" }
sdist = { url = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/files/breakshaft/0.1.1.post1/breakshaft-0.1.1.post1.tar.gz", hash = "sha256:0c880a57eb53122cd1d5c7d2f2520d9f536edd7fac333496da72cc0fa7bf5283" }
wheels = [
{ url = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/files/breakshaft/0.1.0.post2/breakshaft-0.1.0.post2-py3-none-any.whl", hash = "sha256:fd4c9b213e2569c2c4d4f86cef2fe04065c08f9bffac3aa46b8ae21459f35074" },
{ url = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/files/breakshaft/0.1.1.post1/breakshaft-0.1.1.post1-py3-none-any.whl", hash = "sha256:46895336aee55b3fbd0664a2f2deb73a04f15f1dc3ac382fa17884bad4c0f818" },
]
[[package]]
@@ -380,7 +380,7 @@ xml = [
[package.metadata]
requires-dist = [
{ name = "breakshaft", specifier = ">=0.1.0", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" },
{ name = "breakshaft", specifier = ">=0.1.1", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" },
{ name = "case-insensitive-dictionary", specifier = ">=0.2.1" },
{ name = "megasniff", specifier = ">=0.2.0", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" },
{ name = "mypy", specifier = ">=1.17.0" },