4
1
Fork 1

Add validation check function

- Init static module
- Init static.abc
- Init static.functions
- Add IValidatable intefrace
- Add validate function
This commit is contained in:
trueold89 2024-08-03 10:43:09 +03:00
parent 84471f1001
commit 8656f1e68e
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
4 changed files with 44 additions and 1 deletions

View File

@ -8,5 +8,5 @@ setup(
author_email="root@orudo.ru", 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.)", 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"], install_requires=["aiohttp>=3.10.0"],
packages=["tubot"], packages=["tubot", "tubot.static"],
) )

0
tubot/static/__init__.py Normal file
View File

24
tubot/static/abc.py Normal file
View File

@ -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

19
tubot/static/functions.py Normal file
View File

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