config.path

配置数据路径

Classes

AttrKey

属性键

IndexKey

下标键

Path

配置数据路径

PathSyntaxParser

路径语法解析器

Module Contents

class AttrKey(key: str, meta: str | None = None)

Bases: IndexMixin[str, collections.abc.Mapping[str, Any]], config.abc.ABCKey[str, collections.abc.Mapping[str, Any]]

属性键

参数:
  • key (str) -- 键名

  • meta (str | None) -- 元信息

抛出:

TypeError -- key不为str时抛出

__contains_inner_element__(data: collections.abc.Mapping[Any, Any]) bool

是否包含内层元素

参数:

data (D) -- 配置数据

返回:

是否包含内层配置数据

返回类型:

bool

在 0.1.4 版本加入.

__deepcopy__(memo: dict[Any, Any]) Self
__delete_inner_element__(data: D) None

删除内层元素

参数:

data (D) -- 配置数据

在 0.1.4 版本加入.

__eq__(other: Any) bool
__get_inner_element__(data: D) D

获取内层元素

参数:

data (D) -- 配置数据

返回:

内层配置数据

返回类型:

D

在 0.1.4 版本加入.

__hash__() int
__len__() int
__repr__() str
__set_inner_element__(data: D, value: Any) None

设置内层元素

参数:
  • data (D) -- 配置数据

  • value (Any) -- 值

在 0.1.4 版本加入.

__str__() str
__supports__(data: Any) tuple[Any, Ellipsis]

检查此键是否支持该配置数据

返回缺失的协议

参数:

data (Any) -- 配置数据

返回:

此键缺失支持的数据类型

返回类型:

tuple

在 0.1.4 版本加入.

__supports_modify__(data: Any) tuple[Any, Ellipsis]

检查此键是否支持修改该配置数据

返回缺失的协议

参数:

data (Any) -- 配置数据

返回:

此键缺失支持的数据类型

返回类型:

tuple

在 0.1.4 版本加入.

unparse() str

还原为可被解析的字符串

在 0.1.1 版本加入.

__slots__ = ()
_key: str
_meta: str | None = None
property key: K

property meta: str | None

元信息

在 0.2.0 版本加入.

class IndexKey(key: int, meta: str | None = None)

Bases: IndexMixin[int, collections.abc.Sequence[Any]], config.abc.ABCKey[int, collections.abc.Sequence[Any]]

下标键

参数:
  • key (int) -- 索引值

  • meta (str) -- 元信息

抛出:

TypeError -- key不为int时抛出

__contains_inner_element__(data: collections.abc.Sequence[Any]) bool

是否包含内层元素

参数:

data (D) -- 配置数据

返回:

是否包含内层配置数据

返回类型:

bool

在 0.1.4 版本加入.

__deepcopy__(memo: dict[Any, Any]) Self
__delete_inner_element__(data: D) None

删除内层元素

参数:

data (D) -- 配置数据

在 0.1.4 版本加入.

__eq__(other: Any) bool
__get_inner_element__(data: D) D

获取内层元素

参数:

data (D) -- 配置数据

返回:

内层配置数据

返回类型:

D

在 0.1.4 版本加入.

__hash__() int
__repr__() str
__set_inner_element__(data: D, value: Any) None

设置内层元素

参数:
  • data (D) -- 配置数据

  • value (Any) -- 值

在 0.1.4 版本加入.

__str__() str
__supports__(data: Any) tuple[Any, Ellipsis]

检查此键是否支持该配置数据

返回缺失的协议

参数:

data (Any) -- 配置数据

返回:

此键缺失支持的数据类型

返回类型:

tuple

在 0.1.4 版本加入.

__supports_modify__(data: Any) tuple[Any, Ellipsis]

检查此键是否支持修改该配置数据

返回缺失的协议

参数:

data (Any) -- 配置数据

返回:

此键缺失支持的数据类型

返回类型:

tuple

在 0.1.4 版本加入.

unparse() str

还原为可被解析的字符串

在 0.1.1 版本加入.

__slots__ = ()
_key: int
_meta: str | None = None
property key: K

property meta: str | None

元信息

在 0.2.0 版本加入.

class Path

Bases: config.abc.ABCPath[AttrKey | IndexKey]

配置数据路径

classmethod from_locate(locate: collections.abc.Iterable[str | int]) Self

从列表解析路径

参数:

locate (Iterable[str | int]) -- 键列表

返回:

解析后的路径

返回类型:

Self

classmethod from_str(string: str) Self

从字符串解析路径

参数:

string (str) -- 路径字符串

返回:

解析后的路径

返回类型:

Self

to_locate() list[str | int]

转换为列表

在 0.1.1 版本加入.

unparse() str
class PathSyntaxParser

路径语法解析器

classmethod parse(string: str) list[AttrKey | IndexKey]

解析字符串为键列表

参数:

string (str) -- 待解析字符串

返回:

键列表

返回类型:

list[AttrKey | IndexKey]

static tokenize(string: str) tuple[str, Ellipsis]

将字符串分词为以开头的有意义片段

参数:

string (str) -- 待分词字符串

返回:

分词结果

返回类型:

tuple[str, ...]

备注

可以省略字符串开头的 \.

例如:

r"\.first\.second\.third“

可以简写为

r"first\.second\.third"

在 0.1.4 版本发生变更: 允许省略字符串开头的 \.

更改返回值类型为 tuple[str, ...]

添加缓存