diff options
author | Devaev Maxim <[email protected]> | 2019-04-08 04:58:32 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-08 04:58:32 +0300 |
commit | 9243d2a00c86aa9b5df2b1df20d2ba57be0bed47 (patch) | |
tree | 4d86bf39d432af121fff66a863864719c885d84d /kvmd/validators | |
parent | 7eca51f17b7c2c95b54d4c2b77caa6c8554ef4f4 (diff) |
refactoring
Diffstat (limited to 'kvmd/validators')
-rw-r--r-- | kvmd/validators/__init__.py | 7 | ||||
-rw-r--r-- | kvmd/validators/kvm.py | 21 |
2 files changed, 26 insertions, 2 deletions
diff --git a/kvmd/validators/__init__.py b/kvmd/validators/__init__.py index f4b0f1fa..5556f564 100644 --- a/kvmd/validators/__init__.py +++ b/kvmd/validators/__init__.py @@ -23,8 +23,11 @@ import re from typing import List +from typing import Mapping +from typing import Sequence from typing import Callable from typing import NoReturn +from typing import Union from typing import Any @@ -54,13 +57,13 @@ def check_not_none_string(arg: Any, name: str, strip: bool=True) -> str: return arg -def check_in_list(arg: Any, name: str, variants: List) -> Any: +def check_in_list(arg: Any, name: str, variants: Union[Sequence, Mapping]) -> Any: if arg not in variants: raise_error(arg, name) return arg -def check_string_in_list(arg: Any, name: str, variants: List[str], lower: bool=True) -> Any: +def check_string_in_list(arg: Any, name: str, variants: Union[Sequence[str], Mapping[str, Any]], lower: bool=True) -> Any: arg = check_not_none_string(arg, name) if lower: arg = arg.lower() diff --git a/kvmd/validators/kvm.py b/kvmd/validators/kvm.py index 034587ef..40f5ced1 100644 --- a/kvmd/validators/kvm.py +++ b/kvmd/validators/kvm.py @@ -22,6 +22,8 @@ from typing import Any +from .. import keymap + from . import check_string_in_list from .basic import valid_number @@ -46,3 +48,22 @@ def valid_stream_quality(arg: Any) -> int: def valid_stream_fps(arg: Any) -> int: return int(valid_number(arg, min=0, max=30, name="stream FPS")) + + +# ===== +def valid_hid_key(arg: Any) -> str: + return check_string_in_list(arg, "HID key", keymap.KEYMAP, lower=False) + + +def valid_hid_mouse_move(arg: Any) -> int: + arg = valid_number(arg, name="HID mouse move") + return min(max(-32768, arg), 32767) + + +def valid_hid_mouse_button(arg: Any) -> str: + return check_string_in_list(arg, "HID mouse button", ["left", "right"]) + + +def valid_hid_mouse_wheel(arg: Any) -> int: + arg = valid_number(arg, name="HID mouse wheel") + return min(max(-128, arg), 127) |