From e40c4290c9f4d14cad6283a761dda2585ff85f1c Mon Sep 17 00:00:00 2001 From: aerinon Date: Thu, 19 May 2022 12:20:30 -0600 Subject: [PATCH] Fix yaml parsing --- source/classes/CustomSettings.py | 13 +++++-------- source/tools/MysteryUtils.py | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/source/classes/CustomSettings.py b/source/classes/CustomSettings.py index c31e628f..016b3b64 100644 --- a/source/classes/CustomSettings.py +++ b/source/classes/CustomSettings.py @@ -334,12 +334,9 @@ class CustomSettings(object): def load_yaml(path): - try: - return yaml.load(path, Loader=yaml.SafeLoader) - except yaml.YAMLError as exc: - if os.path.exists(Path(path)): - with open(path, "r", encoding="utf-8") as f: - return yaml.load(f, Loader=yaml.SafeLoader) - elif urllib.parse.urlparse(path).scheme in ['http', 'https']: - return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) + if os.path.exists(Path(path)): + with open(path, "r", encoding="utf-8") as f: + return yaml.load(f, Loader=yaml.SafeLoader) + elif urllib.parse.urlparse(path).scheme in ['http', 'https']: + return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) diff --git a/source/tools/MysteryUtils.py b/source/tools/MysteryUtils.py index 9df4eca4..415433c0 100644 --- a/source/tools/MysteryUtils.py +++ b/source/tools/MysteryUtils.py @@ -9,14 +9,11 @@ import yaml def get_weights(path): - try: - return yaml.load(path, Loader=yaml.SafeLoader) - except yaml.YAMLError as exc: - if os.path.exists(Path(path)): - with open(path, "r", encoding="utf-8") as f: - return yaml.load(f, Loader=yaml.SafeLoader) - elif urllib.parse.urlparse(path).scheme in ['http', 'https']: - return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) + if os.path.exists(Path(path)): + with open(path, "r", encoding="utf-8") as f: + return yaml.load(f, Loader=yaml.SafeLoader) + elif urllib.parse.urlparse(path).scheme in ['http', 'https']: + return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) def roll_settings(weights):