refactor: 对配置处理器和配置结构进行重构

This commit is contained in:
2026-04-20 01:44:43 +08:00
parent 5c43059518
commit a38fd3d398
36 changed files with 1097 additions and 917 deletions
+30
View File
@@ -0,0 +1,30 @@
def epath(dct, path: str = '', default=None, parents=False):
if not path:
return dct
path = path.rstrip('/')
target = dct
for i in path.split('/'):
# 处理字典键
if isinstance(target, dict) and i in target:
target = target[i]
# 处理列表索引
elif i.startswith('[') and i.endswith(']') and isinstance(target, (list, tuple)):
idx = int(i[1:-1])
if 0 <= idx < len(target):
target = target[idx]
elif parents:
while len(target) <= idx:
target.append(None)
target[idx] = {}
target = target[idx]
else:
return default
elif parents:
target[i] = {}
target = target[i]
else:
return default
return target