From 843edb911f506842e6c1feb1f4c21e6c78417fef Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 19 Dec 2024 00:19:03 +0100 Subject: [PATCH] Move esmerald Response transform to lilya (#116) * move esmerald response transform to lilya * bump version --- docs/en/docs/release-notes.md | 1 + lilya/__init__.py | 2 +- lilya/responses.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6615409..deda956 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -16,6 +16,7 @@ hide: ### Changed - Move simplify logic from `make_response` to Response but keep old interface. +- Move esmerald Response `transform` to lilya. ### Fixed diff --git a/lilya/__init__.py b/lilya/__init__.py index be37974..eec2a4d 100644 --- a/lilya/__init__.py +++ b/lilya/__init__.py @@ -1 +1 @@ -__version__ = "0.11.6" +__version__ = "0.11.7" diff --git a/lilya/responses.py b/lilya/responses.py index d04a2b8..9901cf1 100644 --- a/lilya/responses.py +++ b/lilya/responses.py @@ -92,6 +92,13 @@ def with_transform_kwargs(cls, params: dict | None, /) -> Generator[None, None, finally: RESPONSE_TRANSFORM_KWARGS.reset(token) + @classmethod + def transform(cls, content: Any) -> Any: + transform_kwargs = RESPONSE_TRANSFORM_KWARGS.get() + if transform_kwargs is None: + transform_kwargs = {} + return json_encode(content, **transform_kwargs) + def make_response(self, content: Any) -> bytes | str: """ Makes the Response object type.