Added configtype to wrap valid prefixes.
This commit is contained in:
parent
5fa0228a7e
commit
02a64630aa
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue