From a01db7f3a03b63888cae26f60b35a9ae0df9edbe Mon Sep 17 00:00:00 2001 From: Cathgao <21031564+Cathgao@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:11:20 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E7=89=88rua?= =?UTF-8?q?mel=E6=8A=A5=E9=94=99=20(#494)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/utils/files.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/LittlePaimon/utils/files.py b/LittlePaimon/utils/files.py index fcb8e7d..c411d58 100644 --- a/LittlePaimon/utils/files.py +++ b/LittlePaimon/utils/files.py @@ -6,7 +6,7 @@ from pathlib import Path from ssl import SSLCertVerificationError from typing import Union -from ruamel import yaml +from ruamel.yaml import YAML from .requests import aiorequests @@ -71,8 +71,8 @@ def load_yaml(path: Union[Path, str], encoding: str = 'utf-8'): """ if isinstance(path, str): path = Path(path) - return yaml.load(path.read_text(encoding=encoding), - Loader=yaml.Loader) if path.exists() else {} + yaml=YAML(typ='safe') + return yaml.load(path.read_text(encoding=encoding)) if path.exists() else {} def save_yaml(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'): @@ -87,9 +87,7 @@ def save_yaml(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8' path = Path(path) path.parent.mkdir(parents=True, exist_ok=True) with path.open('w', encoding=encoding) as f: + yaml=YAML(typ='safe') yaml.dump( data, - f, - indent=2, - Dumper=yaml.RoundTripDumper, - allow_unicode=True) + f)