4
1
Fork 1
This repository has been archived on 2024-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
qBitDownload-Bot/tubot/static/abc.py

50 lines
1.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
##########################################
# Shared Abstract classes and interfaces #
##########################################
# Imports
from abc import ABC, abstractmethod
from os import environ
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
class ENV(object):
_name: str | None = None
DEFAULT: str
def __init__(self) -> None:
if self._name is None or self.DEFAULT is None:
raise NotImplementedError
@property
def from_os(self) -> str | None:
if self._name is not None:
return environ.get(self._name)
@property
def value(self) -> str:
val = self.from_os
if val is not None:
return val
return self.DEFAULT
def __call__(self) -> str:
return self.value