diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 4439cd4f4..55676207f 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -142,6 +142,27 @@ class ValidValues: self.descriptions == other.descriptions) +class ValidPrefixes(ValidValues): + + def __init__(self, *values, separator: str = ':', **kwargs): + super().__init__(*values, **kwargs) + self.separator = separator + + def __contains__(self, item) -> bool: + return any(map(lambda x: item.startswith(x + self.separator), self.values)) + + def __iter__(self) -> Iterator[str]: + return map(lambda x: x + self.separator, super().__iter__()) + + def __repr__(self) -> str: + return utils.get_repr(self, values=self.values, separator=self.separator, + descriptions=self.descriptions) + + def __eq__(self, other: object) -> bool: + assert (isinstance(other, ValidPrefixes)) + return super().__eq__(other) and self.separator == other.separator + + class BaseType: """A type used for a setting value.