select formatter, docstring update
This commit is contained in:
parent
c838447423
commit
50634e86b9
3 changed files with 26 additions and 3 deletions
|
|
@ -10,7 +10,6 @@ class StringFormatterValidator(StringValidator):
|
|||
Ensures user-created formatter strings are valid
|
||||
"""
|
||||
|
||||
expected_value_type = str
|
||||
expected_value_type_name = "format string"
|
||||
|
||||
FIELDS_VALIDATOR = re.compile(r"{([a-z_]+?)}")
|
||||
|
|
|
|||
22
ytdl_subscribe/validators/base/string_select_validator.py
Normal file
22
ytdl_subscribe/validators/base/string_select_validator.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import re
|
||||
from keyword import iskeyword
|
||||
from typing import List
|
||||
from typing import Set
|
||||
|
||||
from ytdl_subscribe.validators.base.validators import StringValidator
|
||||
|
||||
|
||||
class StringSelectValidator(StringValidator):
|
||||
"""
|
||||
Ensures strings have selected one of the discrete allowed values.
|
||||
"""
|
||||
|
||||
select_values: Set[str] = set()
|
||||
|
||||
def __init__(self, name, format_string: str):
|
||||
super().__init__(name=name, value=format_string)
|
||||
|
||||
if self.value not in self.select_values:
|
||||
raise self._validation_exception(
|
||||
f"Must be one of the following values: {', '.join(self.select_values)}"
|
||||
)
|
||||
|
|
@ -9,10 +9,12 @@ from ytdl_subscribe.validators.exceptions import ValidationException
|
|||
|
||||
class Validator:
|
||||
"""
|
||||
Abstract class used to validate any kind of field. Will ensure the value is the specified type.
|
||||
Used to validate the value of a python object. This is the 'base' class that will first
|
||||
check that the value's type matches the expected type. Validators that inherit from this should
|
||||
perform their validation within the __init__.
|
||||
"""
|
||||
|
||||
# The python type that value should be
|
||||
# If the value is not this expected type, error
|
||||
expected_value_type: Type = object
|
||||
|
||||
# When raising an error, call the type this value instead of its python name
|
||||
|
|
|
|||
Loading…
Reference in a new issue