config.main =========== .. py:module:: config.main .. autoapi-nested-parse:: 主要部分 Attributes ---------- .. autoapisummary:: config.main.DefaultConfigPool config.main.get config.main.load config.main.requireConfig config.main.save config.main.saveAll config.main.set_ Classes ------- .. autoapisummary:: config.main.BasicChainConfigSL config.main.BasicCompressedConfigSL config.main.BasicConfigSL config.main.BasicLocalFileConfigSL config.main.ConfigPool config.main.ConfigRequirementDecorator config.main.RequiredPath Functions --------- .. autoapisummary:: config.main.raises Module Contents --------------- .. py:class:: BasicChainConfigSL(*, reg_alias: str | None = None, create_dir: bool = True) Bases: :py:obj:`BasicConfigSL`, :py:obj:`abc.ABC` 基础连锁配置文件SL处理器 .. caution:: 会临时在配置文件池中添加文件以传递SL操作 .. versionadded:: 0.2.0 :param reg_alias: 处理器别名 :type reg_alias: Optional[str] :param create_dir: 是否创建目录 :type create_dir: bool .. py:method:: __eq__(other: Any) -> bool .. py:method:: __hash__() -> int .. py:method:: after_save(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], file_path: str, root_path: str, namespace: str, file_name: str) -> None 保存后处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile[Any] :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: before_load(config_pool: config.abc.ABCConfigPool, file_path: str, root_path: str, namespace: str, file_name: str) -> None 加载前处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: filename_formatter(file_name: str) -> str 格式化文件名以传递给其他SL处理器 :param file_name: 配置文件名 :type file_name: str :return: 格式化后的文件名 :rtype: str 默认实现: - 遍历 :py:attr:`BasicCompressedConfigSL` - 如果为 ``str`` 且 ``file_name.endswith`` 成立则返回移除后缀后的结果 - 如果为 ``re.Pattern`` 且 ``Pattern.fullmatch(file_name)`` 成立则返回 ``Pattern.sub(file_name, "")`` - 直接返回 .. py:method:: initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 初始化一个受SL处理器支持的配置文件 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile .. versionadded:: 0.2.0 .. py:method:: load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 删除参数 ``config_file_cls`` 添加参数 ``processor_pool`` .. py:method:: load_file(config_pool: config.abc.ABCConfigPool, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str :return: 配置文件 :rtype: ABCConfigFile[Any] .. caution:: 传递SL处理前没有清理已经缓存在配置池里的配置文件,返回的可能不是最新数据 .. py:method:: namespace_formatter(namespace: str, file_name: str) -> str 格式化命名空间以传递给其他SL处理器 :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 格式化后的命名空间 :rtype: str .. py:method:: register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) -> Self 注册到配置池中 :param config_pool: 配置池 :type config_pool: ABCSLProcessorPool | None :return: 返回当前实例便于链式调用 :rtype: Self .. versionchanged:: 0.3.0 返回当前实例便于链式调用 .. py:method:: save(processor_pool: config.abc.ABCSLProcessorPool, config_file: config.abc.ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None 保存处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param config_file: 待保存配置 :type config_file: ABCConfigFile :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 添加参数 ``processor_pool`` .. py:method:: save_file(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None 保存指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:attribute:: __slots__ :value: () .. py:attribute:: _cleanup_registry :type: bool :value: True 自动清理为了传递SL处理所加入配置池的配置文件 .. py:attribute:: _reg_alias :type: str | None :value: None .. py:attribute:: create_dir :value: True .. py:property:: processor_reg_name :type: str :abstractmethod: SL处理器的默认注册名 .. py:attribute:: raises .. py:property:: reg_alias :type: str | None 处理器的别名 .. py:property:: reg_name :type: str 处理器的注册名 .. py:property:: supported_file_classes :type: list[type[ABCConfigFile[Any]]] :abstractmethod: :return: 支持的配置文件类 .. versionadded:: 0.2.0 .. py:property:: supported_file_patterns :type: tuple[str | re.Pattern[Any], Ellipsis] :abstractmethod: :return: 支持的文件名匹配 .. versionchanged:: 0.2.0 重命名 ``file_ext`` 为 ``supported_file_patterns`` .. py:class:: BasicCompressedConfigSL(*, reg_alias: str | None = None, create_dir: bool = True) Bases: :py:obj:`BasicCachedConfigSL`, :py:obj:`abc.ABC` 基础压缩配置文件SL处理器 .. versionadded:: 0.2.0 :param reg_alias: 处理器别名 :type reg_alias: Optional[str] :param create_dir: 是否创建目录 :type create_dir: bool .. py:method:: __eq__(other: Any) -> bool .. py:method:: __hash__() -> int .. py:method:: after_save(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], file_path: str, root_path: str, namespace: str, file_name: str) -> None 保存后处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile[Any] :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: before_load(config_pool: config.abc.ABCConfigPool, file_path: str, root_path: str, namespace: str, file_name: str) -> None 加载前处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: compress_file(file_path: str, extract_dir: str) -> None :abstractmethod: 压缩文件 :param file_path: 压缩文件路径 :type file_path: str :param extract_dir: 解压目录 :type extract_dir: str .. py:method:: extract_file(file_path: str, extract_dir: str) -> None :abstractmethod: 解压文件 :param file_path: 压缩文件路径 :type file_path: str :param extract_dir: 解压目录 :type extract_dir: str .. py:method:: filename_formatter(file_name: str) -> str 格式化文件名以传递给其他SL处理器 :param file_name: 配置文件名 :type file_name: str :return: 格式化后的文件名 :rtype: str 默认实现: - 遍历 :py:attr:`BasicCompressedConfigSL` - 如果为 ``str`` 且 ``file_name.endswith`` 成立则返回移除后缀后的结果 - 如果为 ``re.Pattern`` 且 ``Pattern.fullmatch(file_name)`` 成立则返回 ``Pattern.sub(file_name, "")`` - 直接返回 .. py:method:: initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 初始化一个受SL处理器支持的配置文件 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile .. versionadded:: 0.2.0 .. py:method:: load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 删除参数 ``config_file_cls`` 添加参数 ``processor_pool`` .. py:method:: load_file(config_pool: config.abc.ABCConfigPool, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str :return: 配置文件 :rtype: ABCConfigFile[Any] .. caution:: 传递SL处理前没有清理已经缓存在配置池里的配置文件,返回的可能不是最新数据 .. py:method:: namespace_formatter(namespace: str, file_name: str) -> str 格式化命名空间以传递给其他SL处理器 :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 格式化后的命名空间 :rtype: str .. py:method:: register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) -> Self 注册到配置池中 :param config_pool: 配置池 :type config_pool: ABCSLProcessorPool | None :return: 返回当前实例便于链式调用 :rtype: Self .. versionchanged:: 0.3.0 返回当前实例便于链式调用 .. py:method:: save(processor_pool: config.abc.ABCSLProcessorPool, config_file: config.abc.ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None 保存处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param config_file: 待保存配置 :type config_file: ABCConfigFile :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 添加参数 ``processor_pool`` .. py:method:: save_file(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None 保存指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:attribute:: __slots__ :value: () .. py:attribute:: _cleanup_registry :type: bool :value: True 自动清理为了传递SL处理所加入配置池的配置文件 .. py:attribute:: _reg_alias :type: str | None :value: None .. py:attribute:: create_dir :value: True .. py:property:: namespace_suffix :type: str 命名空间后缀 .. py:property:: processor_reg_name :type: str :abstractmethod: SL处理器的默认注册名 .. py:attribute:: raises .. py:property:: reg_alias :type: str | None 处理器的别名 .. py:property:: reg_name :type: str 处理器的注册名 .. py:property:: supported_file_classes :type: list[type[ABCConfigFile[Any]]] :abstractmethod: :return: 支持的配置文件类 .. versionadded:: 0.2.0 .. py:property:: supported_file_patterns :type: tuple[str | re.Pattern[Any], Ellipsis] :abstractmethod: :return: 支持的文件名匹配 .. versionchanged:: 0.2.0 重命名 ``file_ext`` 为 ``supported_file_patterns`` .. py:class:: BasicConfigSL(*, reg_alias: str | None = None) Bases: :py:obj:`config.abc.ABCConfigSL`, :py:obj:`abc.ABC` 基础配置SL管理器 提供了一些实用功能 .. versionchanged:: 0.2.0 重命名 ``BaseConfigSL`` 为 ``BasicConfigSL`` :param reg_alias: sl处理器注册别名 :type reg_alias: Optional[str] .. py:method:: __eq__(other: Any) -> bool .. py:method:: __hash__() -> int .. py:method:: initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 初始化一个受SL处理器支持的配置文件 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile .. versionadded:: 0.2.0 .. py:method:: load(processor_pool: ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> ABCConfigFile[Any] :abstractmethod: 加载处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 删除参数 ``config_file_cls`` 添加参数 ``processor_pool`` .. py:method:: register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) -> Self 注册到配置池中 :param config_pool: 配置池 :type config_pool: ABCSLProcessorPool | None :return: 返回当前实例便于链式调用 :rtype: Self .. versionchanged:: 0.3.0 返回当前实例便于链式调用 .. py:method:: save(processor_pool: ABCSLProcessorPool, config_file: ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None :abstractmethod: 保存处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param config_file: 待保存配置 :type config_file: ABCConfigFile :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 添加参数 ``processor_pool`` .. py:attribute:: __slots__ :value: () .. py:attribute:: _reg_alias :type: str | None :value: None .. py:property:: processor_reg_name :type: str :abstractmethod: SL处理器的默认注册名 .. py:property:: reg_alias :type: str | None 处理器的别名 .. py:property:: reg_name :type: str 处理器的注册名 .. py:property:: supported_file_classes :type: list[type[ABCConfigFile[Any]]] :abstractmethod: :return: 支持的配置文件类 .. versionadded:: 0.2.0 .. py:property:: supported_file_patterns :type: tuple[str | re.Pattern[Any], Ellipsis] :abstractmethod: :return: 支持的文件名匹配 .. versionchanged:: 0.2.0 重命名 ``file_ext`` 为 ``supported_file_patterns`` .. py:class:: BasicLocalFileConfigSL(s_arg: config.abc.SLArgumentType = None, l_arg: config.abc.SLArgumentType = None, *, reg_alias: str | None = None, create_dir: bool = True) Bases: :py:obj:`BasicConfigSL`, :py:obj:`abc.ABC` 基础本地配置文件SL处理器 .. versionchanged:: 0.2.0 重命名从 ``BaseLocalFileConfigSL`` 为 ``BasicLocalFileConfigSL`` :param s_arg: 保存器默认参数 :type s_arg: SLArgumentType :param l_arg: 加载器默认参数 :type l_arg: SLArgumentType :param reg_alias: sl处理器注册别名 :type reg_alias: Optional[str] :param create_dir: 是否允许创建目录 :type create_dir: bool .. versionchanged:: 0.2.0 将 ``保存加载器参数`` 相关从 :py:class:`BasicConfigSL` 移动到此类 .. py:method:: __eq__(other: Any) -> bool .. py:method:: __hash__() -> int .. py:method:: initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 初始化一个受SL处理器支持的配置文件 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile .. versionadded:: 0.2.0 .. py:method:: load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 现在操作是原子的(操作过程发生异常会回滚操作) 现在操作是理论上是多线/进程安全的 删除参数 ``config_file_cls`` 添加参数 ``processor_pool`` .. py:method:: load_file(source_file: Any, *merged_args: Any, **merged_kwargs: Any) -> config.abc.ABCConfigFile[Any] :abstractmethod: 从文件加载配置 :param source_file: 源文件对象 :type source_file: Any :param merged_args: 合并后的位置参数 :param merged_kwargs: 合并后的关键字参数 :return: 本地配置文件对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 删除参数 ``config_file_cls`` 更改 ``source_file`` 参数类型为 ``Any`` .. py:method:: register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) -> Self 注册到配置池中 :param config_pool: 配置池 :type config_pool: ABCSLProcessorPool | None :return: 返回当前实例便于链式调用 :rtype: Self .. versionchanged:: 0.3.0 返回当前实例便于链式调用 .. py:method:: save(processor_pool: config.abc.ABCSLProcessorPool, config_file: config.abc.ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> None 保存处理器 (原子操作 多线/进程安全) :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param config_file: 待保存配置 :type config_file: ABCConfigFile :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 现在操作是原子的(操作过程发生异常会回滚操作) 现在操作是理论上是多线/进程安全的 添加参数 ``processor_pool`` .. py:method:: save_file(config_file: config.abc.ABCConfigFile[Any], target_file: Any, *merged_args: Any, **merged_kwargs: Any) -> None :abstractmethod: 将配置保存到文件 :param config_file: 配置文件 :type config_file: ABCConfigFile :param target_file: 目标文件对象 :type target_file: Any :param merged_args: 合并后的位置参数 :param merged_kwargs: 合并后的关键字参数 :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 更改 ``target_file`` 参数类型为 ``Any`` .. py:attribute:: __slots__ :value: () .. py:attribute:: _l_open_kwargs :type: dict[str, Any] .. py:attribute:: _loader_args :type: config.utils.FrozenArguments .. py:attribute:: _reg_alias :type: str | None :value: None .. py:attribute:: _s_open_kwargs :type: dict[str, Any] .. py:attribute:: _saver_args :type: config.utils.FrozenArguments .. py:attribute:: create_dir :value: True .. py:property:: loader_args :type: config.utils.FrozenArguments 加载器默认参数 .. py:property:: processor_reg_name :type: str :abstractmethod: SL处理器的默认注册名 .. py:attribute:: raises .. py:property:: reg_alias :type: str | None 处理器的别名 .. py:property:: reg_name :type: str 处理器的注册名 .. py:property:: saver_args :type: config.utils.FrozenArguments 保存器默认参数 .. py:property:: supported_file_classes :type: list[type[ABCConfigFile[Any]]] :abstractmethod: :return: 支持的配置文件类 .. versionadded:: 0.2.0 .. py:property:: supported_file_patterns :type: tuple[str | re.Pattern[Any], Ellipsis] :abstractmethod: :return: 支持的文件名匹配 .. versionchanged:: 0.2.0 重命名 ``file_ext`` 为 ``supported_file_patterns`` .. py:class:: ConfigPool Bases: :py:obj:`config.basic.core.BasicConfigPool` 配置池 .. py:method:: require(namespace: str, file_name: str, validator: Any, validator_factory: Any = ValidatorTypes.DEFAULT, static_config: Any | None = None, **kwargs: Any) -> ConfigRequirementDecorator 获取配置 :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str :param validator: 详见 :py:class:`RequiredPath` :param validator_factory: 详见 :py:class:`RequiredPath` :param static_config: 详见 :py:class:`RequiredPath` :param kwargs: 详见 :py:class:`ConfigRequirementDecorator` :return: 详见 :py:class:`ConfigRequirementDecorator` :rtype: :py:class:`ConfigRequirementDecorator` .. versionchanged:: 0.2.0 删除声明于 ``ABCConfigPool`` .. py:class:: ConfigRequirementDecorator(config_pool: config.abc.ABCConfigPool, namespace: str, file_name: str, required: RequiredPath[Any, ConfigRequirementDecorator.__init__.D], *, validate_only: bool = True, config_formats: str | collections.abc.Iterable[str] | None = None, allow_initialize: bool = True, config_cacher: collections.abc.Callable[[collections.abc.Callable[Ellipsis, ConfigRequirementDecorator.__init__.D], VarArg(), KwArg()], ConfigRequirementDecorator.__init__.D] | None = None, filter_kwargs: dict[str, Any] | None = None) 配置获取器,可作装饰器使用 .. versionchanged:: 0.2.0 重命名 ``RequireConfigDecorator`` 为 ``ConfigRequirementDecorator`` .. versionchanged:: 0.3.0 修正配置加载逻辑,现在会在每一次获取配置数据时尝试加载而不是仅在初始化时尝试加载 :param config_pool: 所在的配置池 :type config_pool: ConfigPool :param namespace: 详见 :py:meth:`ConfigPool.load` :param file_name: 详见 :py:meth:`ConfigPool.load` :param required: 需求的键 :type required: RequiredPath[Any, D] :param validate_only: 如果为 :py:const:`True` 则返回配置池中完整的配置数据(按引用传递),否则返回验证后的数据(按值传递), 此选项有助于避免意外修改配置池中的数据 :type validate_only: bool :param config_formats: 详见 :py:meth:`ConfigPool.load` :param allow_initialize: 详见 :py:meth:`ConfigPool.load` :param config_cacher: 缓存配置的装饰器,默认为None,即不缓存 :type config_cacher: Callable[[Callable[..., D], VarArg(), KwArg()], D] | None :param filter_kwargs: :py:meth:`RequiredPath.filter` 要绑定的默认参数,这会导致 ``static_config`` 失效 :type filter_kwargs: dict[str, Any] | None :raise UnsupportedConfigFormatError: 不支持的配置格式 .. versionchanged:: 0.2.0 重命名参数 ``cache_config`` 为 ``config_cacher`` 重命名参数 ``allow_create`` 为 ``allow_initialize`` .. versionadded:: 0.3.0 添加参数 ``validate_only`` .. py:method:: __call__(func: collections.abc.Callable[[config.abc.ABCConfigData, Any], Any]) -> collections.abc.Callable[Ellipsis, Any] 通过装饰器提供配置数据注入,配置数据将会注入到 ``self`` (如果为方法而不是函数)后的第一个参数 :param func: 需要装饰的函数 :type func: Callable[[ABCConfigData, Any], Any] :return: 装饰后的函数 :rtype: Callable[..., Any] .. py:method:: _wrapped_filter(**kwargs: Any) -> config.abc.ABCConfigData .. py:method:: check(*, ignore_cache: bool = False, **filter_kwargs: Any) -> Any 手动检查配置 :param ignore_cache: 是否忽略缓存 :type ignore_cache: bool :param filter_kwargs: RequiredConfig.filter的参数 :return: 得到的配置数据 :rtype: Any .. py:attribute:: _config_cacher :type: collections.abc.Callable[[collections.abc.Callable[Ellipsis, ConfigRequirementDecorator.__init__.D], VarArg(), KwArg()], ConfigRequirementDecorator.__init__.D] .. py:attribute:: _config_loader :type: collections.abc.Callable[[], config.abc.ABCConfigFile[ConfigRequirementDecorator.__init__.D]] .. py:attribute:: _filter_kwargs :value: None .. py:attribute:: _required .. py:attribute:: _validate_only :value: True .. py:class:: RequiredPath(validator: V, validator_factory: ValidatorFactoryType[V, D] | config.validators.ValidatorTypes | Literal['custom', 'pydantic', 'component'] | None = ValidatorTypes.DEFAULT, static_config: config.validators.ValidatorOptions | None = None) 对需求的键进行存在检查、类型检查、填充默认值 :param validator: 数据验证器 :type validator: Any :param validator_factory: 数据验证器工厂 :type validator_factory: ValidatorFactoryType[V, D] | validators.ValidatorTypes | Literal["custom", "pydantic", "component"] | None :param static_config: 静态配置 :type static_config: ValidatorOptions | None .. tip:: 提供 ``static_config`` 参数可以避免在 :py:meth:`~RequiredPath.filter` 中反复调用 ``validator_factory`` 以提高性能 ( :py:meth:`~RequiredPath.filter` 未传入验证器选项参数时优化生效,如果传入了则回退到默认行为) .. py:method:: filter(data: D | config.utils.Ref[D], *, allow_modify: bool | None = None, skip_missing: bool | None = None, **extra: Any) -> D 检查过滤需求的键 :param data: 要过滤的原始数据 :type data: D | Ref[D] :param allow_modify: 是否允许值不存在时修改 ``data`` 参数对象填充默认值(即使为False仍然会在结果中填充默认值,但不会修改 ``data`` 参数对象) :type allow_modify: bool | None :param skip_missing: 忽略丢失的键 :type skip_missing: bool | None :param extra: 额外参数 :type extra: Any :return: 处理后的配置数据*快照* :rtype: D :raise ConfigDataTypeError: 配置数据类型错误 :raise RequiredPathNotFoundError: 必要的键未找到 :raise UnknownErrorDuringValidateError: 验证过程中发生未知错误 .. attention:: 返回的配置数据是 `*快照*` .. caution:: 提供了任意配置参数(``allow_modify``, ``skip_missing``, ...)时,这次调用将完全舍弃 `static_config` 使用当前提供的配置参数 这会导致调用 `validator_factory` 产生额外开销(如果你提供 `static_config` 参数是为了避免反复调用 `validator_factory` 的话) .. versionchanged:: 0.2.0 重命名参数 ``ignore_missing`` 为 ``skip_missing`` ``data`` 参数支持 :py:class:`Ref` .. py:attribute:: ValidatorFactories :type: ClassVar[dict[config.validators.ValidatorTypes, ValidatorFactoryType[Any, Any]]] 验证器工厂注册表 .. versionchanged:: 0.2.0 现在待验证的配置数据必须由 :py:class:`~config.utils.Ref` 包装后传入 .. py:attribute:: _validator .. py:attribute:: _validator_factory :type: ValidatorFactoryType[V, D] .. py:function:: raises(excs: type[Exception] | tuple[type[Exception], Ellipsis] = Exception) -> collections.abc.Generator[None, Any, None] 包装意料内的异常 提供给子类的便捷方法 :param excs: 意料内的异常 :type excs: type[Exception] | tuple[type[Exception], ...] :raise FailedProcessConfigFileError: 当触发了对应的异常时 .. versionadded:: 0.1.4 .. versionchanged:: 0.2.0 提取为函数 .. py:data:: DefaultConfigPool 默认配置池 .. py:data:: get :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.get` .. py:data:: load :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.load` .. py:data:: requireConfig :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.require` .. py:data:: save :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.save` .. py:data:: saveAll :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.save_all` .. py:data:: set_ :py:data:`DefaultConfigPool` . :py:meth:`~ConfigPool.set`