1
0

style: 代码格式化

This commit is contained in:
david-ajax
2025-12-13 21:47:37 +08:00
parent a0b327cdbb
commit baa7ac8ee9
64 changed files with 755 additions and 573 deletions

View File

@@ -3,6 +3,7 @@ import pathlib
import toml
import typing
class ConfigFile:
def __init__(self, path: pathlib.Path):
self.path = path
@@ -13,7 +14,7 @@ class ConfigFile:
def _load(self):
"""从文件加载配置数据"""
with open(self.path, 'r') as f:
with open(self.path, "r") as f:
try:
self.data = toml.load(f)
except toml.TomlDecodeError as e:
@@ -28,20 +29,20 @@ class ConfigFile:
def save(self, path: typing.Union[str, pathlib.Path] = ""):
"""保存配置到文件"""
save_path = pathlib.Path(path) if path else self.path
with open(save_path, 'w') as f:
with open(save_path, "w") as f:
toml.dump(self.data, f)
def get(self, key: str, default: typing.Any = None) -> typing.Any:
"""获取配置值,如果不存在返回默认值"""
return self.data.get(key, default)
def __getitem__(self, key: str) -> typing.Any:
return self.data[key]
def __setitem__(self, key: str, value: typing.Any):
self.data[key] = value
self.save()
def __contains__(self, key: str) -> bool:
"""支持 in 语法"""
return key in self.data
return key in self.data