mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
stronger validators
This commit is contained in:
@@ -26,6 +26,7 @@ from typing import List
|
||||
from typing import Mapping
|
||||
from typing import Sequence
|
||||
from typing import Callable
|
||||
from typing import TypeVar
|
||||
from typing import NoReturn
|
||||
from typing import Union
|
||||
from typing import Any
|
||||
@@ -36,6 +37,10 @@ class ValidatorError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
# =====
|
||||
_RetvalSeqT = TypeVar("_RetvalSeqT", bound=Sequence)
|
||||
|
||||
|
||||
# =====
|
||||
def raise_error(arg: Any, name: str, hide: bool=False) -> NoReturn:
|
||||
arg_str = " "
|
||||
@@ -77,6 +82,12 @@ def check_re_match(arg: Any, name: str, pattern: str, strip: bool=True, hide: bo
|
||||
return arg
|
||||
|
||||
|
||||
def check_len(arg: _RetvalSeqT, name: str, limit: int) -> _RetvalSeqT:
|
||||
if len(arg) > limit:
|
||||
raise_error(arg, name)
|
||||
return arg
|
||||
|
||||
|
||||
def check_any(arg: Any, name: str, validators: List[Callable[[Any], Any]]) -> Any:
|
||||
for validator in validators:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user