X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/610f2cc254cf442c895351907be6405f03026903..80ea13437df4c6d57ea503adbdfc9928de8d859c:/nominatim/tokenizer/sanitizers/config.py diff --git a/nominatim/tokenizer/sanitizers/config.py b/nominatim/tokenizer/sanitizers/config.py index 3ff681b9..ce5ce1eb 100644 --- a/nominatim/tokenizer/sanitizers/config.py +++ b/nominatim/tokenizer/sanitizers/config.py @@ -33,7 +33,7 @@ class SanitizerConfig(UserDict): return None if default is None else list(default) if isinstance(values, str): - return [values] + return [values] if values else [] if not isinstance(values, (list, tuple)): raise UsageError(f"Parameter '{param}' must be string or list of strings.") @@ -44,6 +44,20 @@ class SanitizerConfig(UserDict): return values + def get_bool(self, param, default=None): + """ Extract a configuration parameter as a boolean. + The parameter must be one of the yaml boolean values or an + user error will be raised. If `default` is given, then the parameter + may also be missing or empty. + """ + value = self.data.get(param, default) + + if not isinstance(value, bool): + raise UsageError(f"Parameter '{param}' must be a boolean value ('yes' or 'no'.") + + return value + + def get_delimiter(self, default=',;'): """ Return the 'delimiter' parameter in the configuration as a compiled regular expression that can be used to split the names on the