#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/11/3 19:43 # @File : config.py # @Description : """ from typing import Any from flask import Flask from loguru import logger class ConfigHelper: """ The ConfigHelper class is a utility for fetching configuration values from a Flask application. :param app: The Flask application instance from which to fetch configuration values. """ def __init__(self, app: Flask): self.app = app def __getattr__(self, name): """ Get a config value as an attribute. :param name: The name of the config key. :return: The value for the provided key, or None if it does not exist. """ try: return self.app.config[name] except KeyError: logger.error(f'Key {name} error') raise KeyError(f'Key {name} error') def __repr__(self): return f"" def __str__(self): return f"ConfigHelper for app {self.app}"