importimportlibimportosfromcollectionsimportChainMapfromurllib.parseimporturlsplitfromflaskimportConfigfromflask.helpersimportget_root_pathfromgeonature.utils.config_schemaimportGnGeneralSchemaConf,GnPySchemaConffromgeonature.utils.envimportCONFIG_FILEfromgeonature.utils.errorsimportConfigErrorfromgeonature.utils.utilstomlimportload_tomlfrommarshmallowimportEXCLUDEfrommarshmallow.exceptionsimportValidationError__all__=["config","config_frontend"]# Load config from GEONATURE_* env vars and from GEONATURE_SETTINGS python module (if any)config_programmatic=Config(get_root_path("geonature"))config_programmatic.from_prefixed_env(prefix="GEONATURE")if"GEONATURE_SETTINGS"inos.environ:config_programmatic.from_object(os.environ["GEONATURE_SETTINGS"])# Load toml file and override with env & py configconfig_toml=load_toml(CONFIG_FILE)ifCONFIG_FILEelse{}config_toml.update(config_programmatic)# Validate configtry:config_backend=GnPySchemaConf().load(config_toml,unknown=EXCLUDE)config_frontend=GnGeneralSchemaConf().load(config_toml,unknown=EXCLUDE)exceptValidationErrorase:raiseConfigError(CONFIG_FILE,e.messages)config_default={# disable cache for downloaded files (PDF file stat for ex)# TODO: use Flask.get_send_file_max_age(filename) to return 0 only for generated PDF files"SEND_FILE_MAX_AGE_DEFAULT":0,}