🐛 修复新版ruamel报错 (#494)

This commit is contained in:
Cathgao 2024-01-16 16:11:20 +08:00 committed by GitHub
parent a58d86806b
commit a01db7f3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ from pathlib import Path
from ssl import SSLCertVerificationError from ssl import SSLCertVerificationError
from typing import Union from typing import Union
from ruamel import yaml from ruamel.yaml import YAML
from .requests import aiorequests from .requests import aiorequests
@ -71,8 +71,8 @@ def load_yaml(path: Union[Path, str], encoding: str = 'utf-8'):
""" """
if isinstance(path, str): if isinstance(path, str):
path = Path(path) path = Path(path)
return yaml.load(path.read_text(encoding=encoding), yaml=YAML(typ='safe')
Loader=yaml.Loader) if path.exists() else {} 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'): 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 = Path(path)
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
with path.open('w', encoding=encoding) as f: with path.open('w', encoding=encoding) as f:
yaml=YAML(typ='safe')
yaml.dump( yaml.dump(
data, data,
f, f)
indent=2,
Dumper=yaml.RoundTripDumper,
allow_unicode=True)