python-module/${REPO_NAME_SNAKE}/validation.py
2023-07-31 15:57:05 -07:00

12 lines
407 B
Python

from pathlib import Path
from aiopath import AsyncPath
def validate_file_folder(value: str) -> Path:
file_folder_path = Path(value)
if not file_folder_path.exists():
raise FileNotFoundError(f"No such file or folder: {value}")
if not file_folder_path.is_file() and not file_folder_path.is_dir():
raise TypeError(f"Not a file or directory: {value}")
return AsyncPath(value)