forked from OrudoCA/qBitDownload-Bot
Add validation check function
- Init static module - Init static.abc - Init static.functions - Add IValidatable intefrace - Add validate function
This commit is contained in:
parent
84471f1001
commit
8656f1e68e
2
setup.py
2
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"],
|
||||
)
|
||||
|
|
|
@ -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
|
|
@ -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")
|
Loading…
Reference in New Issue