From 1cd41ffbd2410fb3ef2412c940fe43308b3755e6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 30 Jan 2024 08:24:50 +0000 Subject: [PATCH] Updated documentation --- _modules/apis_core/utils/normalize.html | 19 ++++++++----------- _modules/apis_core/utils/settings.html | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/_modules/apis_core/utils/normalize.html b/_modules/apis_core/utils/normalize.html index 2a9c077ec..a0384234f 100644 --- a/_modules/apis_core/utils/normalize.html +++ b/_modules/apis_core/utils/normalize.html @@ -91,23 +91,20 @@

Source code for apis_core.utils.normalize

 # SPDX-License-Identifier: MIT
 
 import re
+import tomllib
 from apis_core.utils.settings import clean_uri_mapping_file
-from yaml import safe_load
 
 
 
[docs] def clean_uri(uri: str) -> str: - if uri: - settings = safe_load(clean_uri_mapping_file().read_text()) - for mapping in settings.get("mappings", []): - domain = mapping["domain"] - regex = mapping["regex"] - replace = mapping["replace"] - if domain in uri: - m = re.match(regex, uri) - if m: - uri = replace.format(m.group(1)) + settings = tomllib.loads(clean_uri_mapping_file().read_text()) + if uri is not None: + for entry in settings.values(): + regex = entry["regex"] + replace = entry["replace"] + if m := re.match(regex, uri): + uri = replace.format(m.group(1)) return uri
diff --git a/_modules/apis_core/utils/settings.html b/_modules/apis_core/utils/settings.html index c9e8e5d50..246b7bc17 100644 --- a/_modules/apis_core/utils/settings.html +++ b/_modules/apis_core/utils/settings.html @@ -90,6 +90,7 @@

Source code for apis_core.utils.settings

 # SPDX-FileCopyrightText: 2023 Birger Schacht
 # SPDX-License-Identifier: MIT
 
+import os
 from pathlib import Path
 from django.conf import settings
 
@@ -105,7 +106,7 @@ 

Source code for apis_core.utils.settings

 
[docs] def clean_uri_mapping_file() -> Path: - default = default_settings() / "URI_replace_settings.yml" + default = Path(__file__).parent / "clean_uri.toml" mapping_file = getattr(settings, "CLEANURI_MAPPINGS", default) return Path(mapping_file)