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" requires-python = ">=3.13"
dependencies = [ dependencies = [
"megasniff>=0.2.0", "megasniff>=0.2.0",
"breakshaft>=0.1.0", "breakshaft>=0.1.1",
"case-insensitive-dictionary>=0.2.1", "case-insensitive-dictionary>=0.2.1",
"mypy>=1.17.0", "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}') raise ValueError(f'Unable to find request schema in handler {fn}')
query_type, body_type, path_type = get_args(req_schema) 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: def none_generator(*args) -> None:
return None return None
if path_type not in [PTYPE, None, Any]: def create_convertor(t, def_type):
p_inflator = self.infl_generator.schema_to_inflator( infl = None
path_type, if t not in [def_type, None, Any]:
strict_mode_override=False, infl = self.infl_generator.schema_to_inflator(
from_type_override=QTYPE t,
) strict_mode_override=False,
fork_with.add(ConversionPoint(p_inflator, path_type, (PTYPE,))) from_type_override=def_type
else: )
fork_with.add(ConversionPoint(none_generator, path_type, (PTYPE,))) 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 = create_convertor(query_type, QTYPE)
q_inflator = self.infl_generator.schema_to_inflator( b_inflator = create_convertor(body_type, BTYPE)
query_type, p_inflator = create_convertor(path_type, PTYPE)
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,)))
if body_type != [BTYPE, None, Any]: fork_with = {q_inflator, b_inflator, p_inflator}
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,)))
def construct_unwrap(q, b, p) -> UnwrappedRequest: def construct_unwrap(q: QTYPE, b: BTYPE, p: PTYPE) -> UnwrappedRequest:
return UnwrappedRequest(q, b, p) return UnwrappedRequest(q, b, p)
fork_with |= { fork_with |= {
ConversionPoint( ConversionPoint(
construct_unwrap, construct_unwrap,
req_schema, 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) tmp_repo = self.inj_repo.fork(fork_with)
conv = tmp_repo.get_conversion( p = tmp_repo.create_pipeline(
(BasicRequest,), (Send, BasicRequest),
fn, [fn, self.send_answer],
force_async=True,
)
out_conv = self.inj_repo.get_conversion(
(Send, BasicRequest, handle_hints['return'],),
self.send_answer,
force_async=True force_async=True
) )
async def pipeline(send: Send, req: BasicRequest): self.router.add(method, path_pattern, p)
ret = await conv(req)
await out_conv(send, req, ret)
self.router.add(method, path_pattern, pipeline)
return fn return fn
return decorator return decorator

8
uv.lock generated
View File

@@ -4,15 +4,15 @@ requires-python = ">=3.13"
[[package]] [[package]]
name = "breakshaft" 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" } source = { registry = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" }
dependencies = [ dependencies = [
{ name = "hatchling" }, { name = "hatchling" },
{ name = "jinja2" }, { 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 = [ 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]] [[package]]
@@ -380,7 +380,7 @@ xml = [
[package.metadata] [package.metadata]
requires-dist = [ 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 = "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 = "megasniff", specifier = ">=0.2.0", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" },
{ name = "mypy", specifier = ">=1.17.0" }, { name = "mypy", specifier = ">=1.17.0" },