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")