This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/main by this push:
     new 29b365d  Use a wrapper for element responses
29b365d is described below

commit 29b365d6dde13f8ffc1a46e18300c0be1fae6a6a
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon Oct 27 19:29:53 2025 +0000

    Use a wrapper for element responses
---
 atr/admin/__init__.py   | 13 ++++++-------
 atr/routes/download.py  |  2 +-
 atr/routes/published.py |  5 +++--
 atr/web.py              |  6 ++++++
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/atr/admin/__init__.py b/atr/admin/__init__.py
index dd23ae7..4c9b1fd 100644
--- a/atr/admin/__init__.py
+++ b/atr/admin/__init__.py
@@ -194,7 +194,7 @@ async def configuration(session: web.Committer) -> 
quart.wrappers.response.Respo
 
 
 @admin.get("/consistency")
-async def consistency(session: web.Committer) -> quart.Response:
+async def consistency(session: web.Committer) -> web.TextResponse:
     """Check for consistency between the database and the filesystem."""
     # Get all releases from the database
     async with db.session() as data:
@@ -218,7 +218,7 @@ async def consistency(session: web.Committer) -> 
quart.Response:
                 database_dirs.remove(database_dir)
                 filesystem_dirs.remove(filesystem_dir)
                 break
-    return quart.Response(
+    return web.TextResponse(
         f"""\
 === BROKEN ===
 
@@ -236,8 +236,7 @@ FILESYSTEM ONLY:
 Paired correctly:
 
 {"\n".join(sorted(paired_dirs or ["-"]))}
-""",
-        mimetype="text/plain",
+"""
     )
 
 
@@ -312,7 +311,7 @@ async def _delete_test_openpgp_keys(session: web.Committer) 
-> quart.Response |
     if quart.request.method != "POST":
         delete_form = await DeleteTestKeysForm.create_form()
         rendered_form = forms.render_simple(delete_form, action="")
-        return quart.Response(str(rendered_form), mimetype="text/html")
+        return web.ElementResponse(rendered_form)
 
     # This is a POST request
     delete_form = await DeleteTestKeysForm.create_form()
@@ -451,7 +450,7 @@ async def _keys_check(session: web.Committer) -> 
quart.Response:
     if quart.request.method != "POST":
         check_form = await CheckKeysForm.create_form()
         rendered_form = forms.render_simple(check_form, action="")
-        return quart.Response(str(rendered_form), mimetype="text/html")
+        return web.ElementResponse(rendered_form)
 
     try:
         result = await _check_keys()
@@ -476,7 +475,7 @@ async def _keys_regenerate_all(session: web.Committer) -> 
quart.Response:
     if quart.request.method != "POST":
         regenerate_form = await RegenerateKeysForm.create_form()
         rendered_form = forms.render_simple(regenerate_form, action="")
-        return quart.Response(str(rendered_form), mimetype="text/html")
+        return web.ElementResponse(rendered_form)
 
     async with db.session() as data:
         committee_names = [c.name for c in await data.committee().all()]
diff --git a/atr/routes/download.py b/atr/routes/download.py
index 1dbb5c5..ff2365b 100644
--- a/atr/routes/download.py
+++ b/atr/routes/download.py
@@ -242,4 +242,4 @@ async def _list(
         div.a(href=link_url)[display_name]
     html.body[div.collect(separator=htm.br)]
     response_body = html.collect()
-    return quart.Response(response_body, mimetype="text/html")
+    return web.ElementResponse(response_body)
diff --git a/atr/routes/published.py b/atr/routes/published.py
index daed201..3db7cab 100644
--- a/atr/routes/published.py
+++ b/atr/routes/published.py
@@ -25,6 +25,7 @@ import quart
 import atr.htm as htm
 import atr.route as route
 import atr.util as util
+import atr.web as web
 
 
 @route.committer("/published/<path:path>")
@@ -41,7 +42,7 @@ async def root(session: route.CommitterSession) -> 
quart.Response:
     return await _path(session, "")
 
 
-async def _directory_listing(full_path: pathlib.Path, current_path: str) -> 
quart.Response:
+async def _directory_listing(full_path: pathlib.Path, current_path: str) -> 
web.ElementResponse:
     html = htm.Block(htm.html)
     html.title[f"Index of /{current_path}"]
     html.style["body { margin: 1rem; }"]
@@ -49,7 +50,7 @@ async def _directory_listing(full_path: pathlib.Path, 
current_path: str) -> quar
         htm.h1[f"Index of /{current_path}"]
         with body.block(htm.pre) as pre:
             await _directory_listing_pre(full_path, current_path, pre)
-    return quart.Response(html.collect(), mimetype="text/html")
+    return web.ElementResponse(html.collect())
 
 
 async def _directory_listing_pre(full_path: pathlib.Path, current_path: str, 
pre: htm.Block) -> None:
diff --git a/atr/web.py b/atr/web.py
index 1bfa057..d92f3db 100644
--- a/atr/web.py
+++ b/atr/web.py
@@ -25,6 +25,7 @@ import quart
 
 import atr.config as config
 import atr.db as db
+import atr.htm as htm
 import atr.models.sql as sql
 import atr.user as user
 import atr.util as util
@@ -171,6 +172,11 @@ class Committer:
         return self._projects[:]
 
 
+class ElementResponse(quart.Response):
+    def __init__(self, element: htm.Element, status: int = 200) -> None:
+        super().__init__(str(element), status=status, mimetype="text/html")
+
+
 class RouteFunction(Protocol[R]):
     """Protocol for @app_route decorated functions."""
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to