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.
2024-08-03 07:43:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Shared Abstract classes and interfaces #
|
|
|
|
##########################################
|
|
|
|
|
|
|
|
# Imports
|
|
|
|
from abc import ABC, abstractmethod
|
2024-08-05 14:43:58 +00:00
|
|
|
from os import environ
|
2024-08-03 07:43:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-08-05 14:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|