summaryrefslogtreecommitdiff
path: root/kvmd/validators
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
committerMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
commitee3e224e396494cd0d69bb6167087a071a20349c (patch)
tree5becd28570e58a03c6e1e231d0db24c264a73f88 /kvmd/validators
parent4b75221e9470b4a009955d7677f16adf8e23e302 (diff)
new typing style
Diffstat (limited to 'kvmd/validators')
-rw-r--r--kvmd/validators/__init__.py9
-rw-r--r--kvmd/validators/auth.py3
-rw-r--r--kvmd/validators/basic.py15
-rw-r--r--kvmd/validators/kvm.py3
-rw-r--r--kvmd/validators/net.py11
-rw-r--r--kvmd/validators/os.py5
-rw-r--r--kvmd/validators/ugpio.py9
7 files changed, 21 insertions, 34 deletions
diff --git a/kvmd/validators/__init__.py b/kvmd/validators/__init__.py
index 0e9886cf..db8fb6a7 100644
--- a/kvmd/validators/__init__.py
+++ b/kvmd/validators/__init__.py
@@ -22,14 +22,11 @@
import re
-from typing import List
-from typing import Set
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
@@ -63,7 +60,7 @@ def check_not_none_string(arg: Any, name: str, strip: bool=True) -> str:
return arg
-def check_in_list(arg: Any, name: str, variants: Union[Sequence, Mapping, Set]) -> Any:
+def check_in_list(arg: Any, name: str, variants: (Sequence | Mapping | set)) -> Any:
if arg not in variants:
raise_error(arg, name)
return arg
@@ -72,7 +69,7 @@ def check_in_list(arg: Any, name: str, variants: Union[Sequence, Mapping, Set])
def check_string_in_list(
arg: Any,
name: str,
- variants: Union[Sequence[str], Mapping[str, Any], Set[str]],
+ variants: (Sequence[str] | Mapping[str, Any] | set[str]),
lower: bool=True,
) -> str:
@@ -95,7 +92,7 @@ def check_len(arg: _RetvalSeqT, name: str, limit: int) -> _RetvalSeqT:
return arg
-def check_any(arg: Any, name: str, validators: List[Callable[[Any], Any]]) -> Any: # pylint: disable=inconsistent-return-statements
+def check_any(arg: Any, name: str, validators: list[Callable[[Any], Any]]) -> Any: # pylint: disable=inconsistent-return-statements
for validator in validators:
try:
return validator(arg)
diff --git a/kvmd/validators/auth.py b/kvmd/validators/auth.py
index bb2fad14..025110e6 100644
--- a/kvmd/validators/auth.py
+++ b/kvmd/validators/auth.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-from typing import List
from typing import Any
from .basic import valid_string_list
@@ -33,7 +32,7 @@ def valid_user(arg: Any) -> str:
return check_re_match(arg, "username characters", r"^[a-z_][a-z0-9_-]*$")
-def valid_users_list(arg: Any) -> List[str]:
+def valid_users_list(arg: Any) -> list[str]:
return valid_string_list(arg, subval=valid_user, name="users list")
diff --git a/kvmd/validators/basic.py b/kvmd/validators/basic.py
index e72ad558..059ec226 100644
--- a/kvmd/validators/basic.py
+++ b/kvmd/validators/basic.py
@@ -22,11 +22,8 @@
import re
-from typing import List
from typing import Type
from typing import Callable
-from typing import Optional
-from typing import Union
from typing import Any
from . import ValidatorError
@@ -63,11 +60,11 @@ def valid_bool(arg: Any) -> bool:
def valid_number(
arg: Any,
- min: Union[int, float, None]=None, # pylint: disable=redefined-builtin
- max: Union[int, float, None]=None, # pylint: disable=redefined-builtin
- type: Union[Type[int], Type[float]]=int, # pylint: disable=redefined-builtin
+ min: (int | float | None)=None, # pylint: disable=redefined-builtin
+ max: (int | float | None)=None, # pylint: disable=redefined-builtin
+ type: (Type[int] | Type[float])=int, # pylint: disable=redefined-builtin
name: str="",
-) -> Union[int, float]:
+) -> (int | float):
name = (name or type.__name__)
@@ -103,9 +100,9 @@ def valid_float_f01(arg: Any) -> float:
def valid_string_list(
arg: Any,
delim: str=r"[,\t ]+",
- subval: Optional[Callable[[Any], Any]]=None,
+ subval: (Callable[[Any], Any] | None)=None,
name: str="",
-) -> List[str]:
+) -> list[str]:
if not name:
name = "string list"
diff --git a/kvmd/validators/kvm.py b/kvmd/validators/kvm.py
index a6a6060a..600aa5de 100644
--- a/kvmd/validators/kvm.py
+++ b/kvmd/validators/kvm.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-from typing import Set
from typing import Any
from . import raise_error
@@ -45,7 +44,7 @@ def valid_msd_image_name(arg: Any) -> str:
return valid_printable_filename(arg, name="MSD image name") # pragma: nocover
-def valid_info_fields(arg: Any, variants: Set[str]) -> Set[str]:
+def valid_info_fields(arg: Any, variants: set[str]) -> set[str]:
return set(valid_string_list(
arg=str(arg).strip(),
subval=(lambda field: check_string_in_list(field, "info field", variants)),
diff --git a/kvmd/validators/net.py b/kvmd/validators/net.py
index 2ff8f495..f92dc978 100644
--- a/kvmd/validators/net.py
+++ b/kvmd/validators/net.py
@@ -23,7 +23,6 @@
import ipaddress
import ssl
-from typing import List
from typing import Callable
from typing import Any
@@ -52,8 +51,8 @@ def valid_ip_or_host(arg: Any) -> str:
def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str:
assert v4 or v6
- validators: List[Callable] = []
- versions: List[str] = []
+ validators: list[Callable] = []
+ versions: list[str] = []
if v4:
validators.append(lambda arg: str(ipaddress.IPv4Address(arg)))
versions.append("4")
@@ -70,8 +69,8 @@ def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str:
def valid_net(arg: Any, v4: bool=True, v6: bool=True) -> str:
assert v4 or v6
- validators: List[Callable] = []
- versions: List[str] = []
+ validators: list[Callable] = []
+ versions: list[str] = []
if v4:
validators.append(lambda arg: str(ipaddress.IPv4Network(arg)))
versions.append("4")
@@ -99,7 +98,7 @@ def valid_port(arg: Any) -> int:
return int(valid_number(arg, min=0, max=65535, name="network port"))
-def valid_ports_list(arg: Any) -> List[int]:
+def valid_ports_list(arg: Any) -> list[int]:
return list(map(int, valid_string_list(arg, subval=valid_port, name="ports list")))
diff --git a/kvmd/validators/os.py b/kvmd/validators/os.py
index 4cf107a7..97aabdf0 100644
--- a/kvmd/validators/os.py
+++ b/kvmd/validators/os.py
@@ -23,7 +23,6 @@
import os
import stat
-from typing import List
from typing import Any
from . import raise_error
@@ -94,13 +93,13 @@ def valid_unix_mode(arg: Any) -> int:
return int(valid_number(arg, min=0, name="UNIX mode"))
-def valid_options(arg: Any, name: str="") -> List[str]:
+def valid_options(arg: Any, name: str="") -> list[str]:
if not name:
name = "options"
return valid_string_list(arg, delim=r"[,\t]+", name=name)
-def valid_command(arg: Any) -> List[str]:
+def valid_command(arg: Any) -> list[str]:
cmd = valid_options(arg, name="command")
if len(cmd) == 0:
raise_error(arg, "command")
diff --git a/kvmd/validators/ugpio.py b/kvmd/validators/ugpio.py
index 6f32a26f..c05aa75d 100644
--- a/kvmd/validators/ugpio.py
+++ b/kvmd/validators/ugpio.py
@@ -20,9 +20,6 @@
# ========================================================================== #
-from typing import List
-from typing import Set
-from typing import Optional
from typing import Any
from . import raise_error
@@ -32,7 +29,7 @@ from . import check_len
# =====
-def valid_ugpio_driver(arg: Any, variants: Optional[Set[str]]=None) -> str:
+def valid_ugpio_driver(arg: Any, variants: (set[str] | None)=None) -> str:
name = "GPIO driver"
arg = check_len(check_re_match(arg, name, r"^[a-zA-Z_][a-zA-Z0-9_-]*$"), name, 255)
if variants is not None:
@@ -45,11 +42,11 @@ def valid_ugpio_channel(arg: Any) -> str:
return check_len(check_re_match(arg, name, r"^[a-zA-Z_][a-zA-Z0-9_.-]*$"), name, 255)
-def valid_ugpio_mode(arg: Any, variants: Set[str]) -> str:
+def valid_ugpio_mode(arg: Any, variants: set[str]) -> str:
return check_string_in_list(arg, "GPIO driver's pin mode", variants)
-def valid_ugpio_view_table(arg: Any) -> List[List[str]]: # pylint: disable=inconsistent-return-statements
+def valid_ugpio_view_table(arg: Any) -> list[list[str]]: # pylint: disable=inconsistent-return-statements
try:
return [list(map(str, row)) for row in list(arg)]
except Exception: