config.py 1021 Bytes
Newer Older
崔为之's avatar
崔为之 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/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


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 get_config(self, key: str) -> Any:
        """
        Fetch a config value based on the provided key.

        :param key: The key for the config value.
        :return: The value for the provided key.
        """
        return self.app.config.get(key)

    def __repr__(self):
        return f"<ConfigHelper with app {self.app}>"

    def __str__(self):
        return f"ConfigHelper for app {self.app}"