diff options
author | Nicholas Schwab <git@nicholas-schwab.de> | 2021-04-08 16:20:14 +0200 |
---|---|---|
committer | Nicholas Schwab <git@nicholas-schwab.de> | 2021-04-08 16:20:14 +0200 |
commit | 02a64630aa83e37e47a28a60366e1c65f0eba3ac (patch) | |
tree | e4d47c4ac741182076425de7d83191dc64bb4278 | |
parent | 5fa0228a7efc3b8ea64b7002a198d0a22d0c8cd1 (diff) | |
download | qutebrowser-02a64630aa83e37e47a28a60366e1c65f0eba3ac.tar.gz qutebrowser-02a64630aa83e37e47a28a60366e1c65f0eba3ac.zip |
Added configtype to wrap valid prefixes.
-rw-r--r-- | qutebrowser/config/configtypes.py | 21 |
1 files changed, 21 insertions, 0 deletions
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. |