From c5a7315cf9306f7a604daf170224541a3d45ddf6 Mon Sep 17 00:00:00 2001 From: Maximilian Moser <maximilian.moser@tuwien.ac.at> Date: Tue, 18 Mar 2025 20:12:14 +0100 Subject: [PATCH] Fix incorrect usage of `lstrip()` and `rstrip()` * what we actually want to do is `removeprefix()` and `removesuffix()` --- invenio_config_tuw/notifications/backends.py | 2 +- invenio_config_tuw/startup/config.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/invenio_config_tuw/notifications/backends.py b/invenio_config_tuw/notifications/backends.py index dd7d937..1b85887 100644 --- a/invenio_config_tuw/notifications/backends.py +++ b/invenio_config_tuw/notifications/backends.py @@ -29,7 +29,7 @@ def temp_hack_notification_type(notification): notification, "template_name", notification.context.get("template_name", None) ) if temp_type: - notification.type = temp_type.rstrip(".jinja") + notification.type = temp_type.removesuffix(".jinja") yield notification notification.type = old_notif_type diff --git a/invenio_config_tuw/startup/config.py b/invenio_config_tuw/startup/config.py index 2ed303a..e5f3f62 100644 --- a/invenio_config_tuw/startup/config.py +++ b/invenio_config_tuw/startup/config.py @@ -81,7 +81,7 @@ def _make_site_url(suffix): url = current_app.config.get("THEME_SITEURL", "") # do a little dance to make sure there's no extra slashes - return (url.rstrip("/") + "/" + suffix.lstrip("/")).rstrip("/") + return (url.removesuffix("/") + "/" + suffix.removeprefix("/")).removesuffix("/") def assemble_db_uri_from_parts(app): @@ -186,7 +186,9 @@ def assemble_site_urls_from_parts(app): theme_siteurl = theme_siteurl or f"{preferred_scheme}://{server_name}" elif theme_siteurl: - server_name = theme_siteurl.lstrip("http://").lstrip("https://").split("/")[0] + server_name = ( + theme_siteurl.removeprefix("http://").removeprefix("https://").split("/")[0] + ) app.logger.info( f"No SERVER_NAME set, calculated value '{server_name}' from THEME_SITEURL: '{theme_siteurl}'" ) -- GitLab