<commit_before>import os

from everyclass.server import logger
from everyclass.server.config.default import Config as DefaultConfig


class MixedConfig(DefaultConfig):
    inited = False


def get_config():
    """
    单例配置加载
    :return: Config 类的实例
    """

    if MixedConfig.inited:
        return MixedConfig
    else:
        mode = os.environ.get('MODE')
        _override_config = {}

        try:
            if mode == 'PRODUCTION':
                from everyclass.server.config.production import ProductionConfig
                _override_config = ProductionConfig
                MixedConfig.CONFIG_NAME = 'production'
            elif mode == 'DEVELOPMENT':
                from everyclass.server.config.development import DevelopmentConfig
                _override_config = DevelopmentConfig
                MixedConfig.CONFIG_NAME = 'development'
            elif mode == 'STAGING':
                from everyclass.server.config.staging import StagingConfig
                _override_config = StagingConfig
                MixedConfig.CONFIG_NAME = 'staging'
            elif mode == 'TESTING':
                from everyclass.server.config.testing import TestingConfig
                _override_config = TestingConfig
                MixedConfig.CONFIG_NAME = 'testing'
            else:
                MixedConfig.CONFIG_NAME = 'default'
                logger.error('No valid MODE environment variable specified. Default config will be used.')
        except ImportError:
            logger.critical('ImportError when importing configuration file')
            exit(1)

        for key in dir(_override_config):
            if key.isupper():
                if isinstance(getattr(_override_config, key), dict) \
                        and key in dir(MixedConfig) \
                        and isinstance(getattr(MixedConfig, key), dict):
                    # 字典内容增量覆盖
                    dict_to_modify = getattr(MixedConfig, key)
                    for k, v in getattr(_override_config, key).items():
                        dict_to_modify[k] = v
                    setattr(MixedConfig, key, dict_to_modify)
                else:<commit_msg>change exit code<commit_after>import os

from everyclass.server import logger
from everyclass.server.config.default import Config as DefaultConfig


class MixedConfig(DefaultConfig):
    inited = False


def get_config():
    """
    单例配置加载
    :return: Config 类的实例
    """

    if MixedConfig.inited:
        return MixedConfig
    else:
        mode = os.environ.get('MODE')
        _override_config = {}

        try:
            if mode == 'PRODUCTION':
                from everyclass.server.config.production import ProductionConfig
                _override_config = ProductionConfig
                MixedConfig.CONFIG_NAME = 'production'
            elif mode == 'DEVELOPMENT':
                from everyclass.server.config.development import DevelopmentConfig
                _override_config = DevelopmentConfig
                MixedConfig.CONFIG_NAME = 'development'
            elif mode == 'STAGING':
                from everyclass.server.config.staging import StagingConfig
                _override_config = StagingConfig
                MixedConfig.CONFIG_NAME = 'staging'
            elif mode == 'TESTING':
                from everyclass.server.config.testing import TestingConfig
                _override_config = TestingConfig
                MixedConfig.CONFIG_NAME = 'testing'
            else:
                MixedConfig.CONFIG_NAME = 'default'
                logger.error('No valid MODE environment variable specified. Default config will be used.')
        except ImportError:
            logger.critical('ImportError when importing configuration file')
            exit(2)

        for key in dir(_override_config):
            if key.isupper():
                if isinstance(getattr(_override_config, key), dict) \
                        and key in dir(MixedConfig) \
                        and isinstance(getattr(MixedConfig, key), dict):
                    # 字典内容增量覆盖
                    dict_to_modify = getattr(MixedConfig, key)
                    for k, v in getattr(_override_config, key).items():
                        dict_to_modify[k] = v
                    setattr(MixedConfig, key, dict_to_modify)
                else:
{'fraction_non_alphanumeric': 0.07058823529411765, 'fraction_numerical': 0.000461361014994233, 'mean_word_length': 1.7956157317859445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3612414', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1054, 'n_words': 263}