diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/config.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py index e91c651..b1d588b 100644 --- a/webmentions_ssg/config.py +++ b/webmentions_ssg/config.py @@ -22,6 +22,24 @@ def normalize_allowed_hostnames(value: object) -> set[str]: return hostnames +def normalize_ignored_hostnames(value: object) -> tuple[str, ...]: + """Validate and normalize hostname patterns ignored by the source scanner.""" + if not isinstance(value, (list, tuple, set, frozenset)): + raise TypeError( + "IGNORED_HOSTNAMES must be a list, tuple, or set of hostname patterns, " + "not a string." + ) + + patterns: set[str] = set() + for pattern in value: + if not isinstance(pattern, str) or not ( + normalized := pattern.strip().lower().rstrip(".") + ): + raise ValueError("IGNORED_HOSTNAMES must contain non-empty strings only.") + patterns.add(normalized) + return tuple(sorted(patterns)) + + class DefaultConfig: TESTING = False DEBUG = False @@ -62,6 +80,7 @@ class DefaultConfig: SOURCE_DIRECTORY = None SOURCE_BASE_URL = None + IGNORED_HOSTNAMES = () SCANNER_SCHEDULE = "0 * * * *" # Total send attempts per source revision (not additional retries). SEND_MAX_ATTEMPTS = 6 |
