fixed type errors when pylance type checking mode is strict.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from argparse import _SubParsersAction
|
||||
from typing import Any
|
||||
from unicodedata import normalize
|
||||
|
||||
from mdrsclient.api import FolderApi, LaboratoryApi
|
||||
@ -18,16 +18,18 @@ from mdrsclient.models import Folder, Laboratory
|
||||
class BaseCommand(ABC):
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def register(cls, parsers: _SubParsersAction) -> None:
|
||||
def register(cls, parsers: Any) -> None:
|
||||
raise UnexpectedException("Not implemented.")
|
||||
|
||||
def _create_connection(self, remote: str) -> MDRSConnection:
|
||||
@classmethod
|
||||
def _create_connection(cls, remote: str) -> MDRSConnection:
|
||||
config = ConfigFile(remote)
|
||||
if config.url is None:
|
||||
raise MissingConfigurationException(f"Remote host `{remote}` is not found.")
|
||||
return MDRSConnection(config.remote, config.url)
|
||||
|
||||
def _find_laboratory(self, connection: MDRSConnection, name: str) -> Laboratory:
|
||||
@classmethod
|
||||
def _find_laboratory(cls, connection: MDRSConnection, name: str) -> Laboratory:
|
||||
if connection.laboratories.empty() or connection.token is not None and connection.token.is_expired:
|
||||
laboratory_api = LaboratoryApi(connection)
|
||||
connection.laboratories = laboratory_api.list()
|
||||
@ -36,8 +38,9 @@ class BaseCommand(ABC):
|
||||
raise IllegalArgumentException(f"Laboratory `{name}` not found.")
|
||||
return laboratory
|
||||
|
||||
@classmethod
|
||||
def _find_folder(
|
||||
self, connection: MDRSConnection, laboratory: Laboratory, path: str, password: str | None = None
|
||||
cls, connection: MDRSConnection, laboratory: Laboratory, path: str, password: str | None = None
|
||||
) -> Folder:
|
||||
folder_api = FolderApi(connection)
|
||||
folders = folder_api.list(laboratory.id, normalize("NFC", path))
|
||||
@ -49,14 +52,16 @@ class BaseCommand(ABC):
|
||||
folder_api.auth(folders[0].id, password)
|
||||
return folder_api.retrieve(folders[0].id)
|
||||
|
||||
def _parse_remote_host(self, path: str) -> str:
|
||||
@classmethod
|
||||
def _parse_remote_host(cls, path: str) -> str:
|
||||
path_array = path.split(":")
|
||||
remote_host = path_array[0]
|
||||
if len(path_array) == 2 and path_array[1] != "" or len(path_array) > 2:
|
||||
raise IllegalArgumentException("Invalid remote host")
|
||||
return remote_host
|
||||
|
||||
def _parse_remote_host_with_path(self, path: str) -> tuple[str, str, str]:
|
||||
@classmethod
|
||||
def _parse_remote_host_with_path(cls, path: str) -> tuple[str, str, str]:
|
||||
path = re.sub(r"//+|/\./+|/\.$", "/", path)
|
||||
if re.search(r"/\.\./|/\.\.$", path) is not None:
|
||||
raise IllegalArgumentException("Path traversal found.")
|
||||
|
Reference in New Issue
Block a user