Skip to content

Commit

Permalink
🐛 修复新版ruamel报错 (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cathgao authored Jan 16, 2024
1 parent a58d868 commit a01db7f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions LittlePaimon/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ssl import SSLCertVerificationError
from typing import Union

from ruamel import yaml
from ruamel.yaml import YAML

from .requests import aiorequests

Expand Down Expand Up @@ -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'):
Expand All @@ -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)

0 comments on commit a01db7f

Please sign in to comment.