From 8656f1e68e071a078bc86fde2a923944423e47e7 Mon Sep 17 00:00:00 2001 From: trueold89 Date: Sat, 3 Aug 2024 10:43:09 +0300 Subject: [PATCH] Add validation check function - Init static module - Init static.abc - Init static.functions - Add IValidatable intefrace - Add validate function --- setup.py | 2 +- tubot/static/__init__.py | 0 tubot/static/abc.py | 24 ++++++++++++++++++++++++ tubot/static/functions.py | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tubot/static/__init__.py create mode 100644 tubot/static/abc.py create mode 100644 tubot/static/functions.py diff --git a/setup.py b/setup.py index dcaca7c..285bbb3 100644 --- a/setup.py +++ b/setup.py @@ -8,5 +8,5 @@ setup( author_email="root@orudo.ru", description="A simple Telegram bot that will allow you to upload torrent files / magnet links to a remote Torrent server (qBitTorrent, Transmission, etc.)", install_requires=["aiohttp>=3.10.0"], - packages=["tubot"], + packages=["tubot", "tubot.static"], ) diff --git a/tubot/static/__init__.py b/tubot/static/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tubot/static/abc.py b/tubot/static/abc.py new file mode 100644 index 0000000..d79f1ce --- /dev/null +++ b/tubot/static/abc.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +########################################## +# Shared Abstract classes and interfaces # +########################################## + +# Imports +from abc import ABC, abstractmethod + + +class IValidatable(ABC): + """ + Interface initializing a class with a magic method for + checking the validity of its objects + """ + + @abstractmethod + async def __validate__(self) -> bool: + """ + Checks if the object of the class is valid + + :return: Object validity boolean + """ + raise NotImplementedError diff --git a/tubot/static/functions.py b/tubot/static/functions.py new file mode 100644 index 0000000..72d6821 --- /dev/null +++ b/tubot/static/functions.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +#################### +# Static functions # +#################### + +# Imports +from tubot.static.abc import IValidatable + + +async def validate(obj: IValidatable) -> bool: + """ + Checks the validity of the object + + :return: Object validity boolean + """ + if await obj.__validate__(): + return True + raise TypeError("Object validation failed")