Fix windows absolute path parsing

This commit is contained in:
aerinon
2022-05-19 10:28:19 -06:00
parent 9a6b7c624d
commit 041443be3d
2 changed files with 15 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import urllib.parse
import yaml import yaml
from yaml.representer import Representer from yaml.representer import Representer
from collections import defaultdict from collections import defaultdict
from pathlib import Path
import RaceRandom as random import RaceRandom as random
from BaseClasses import LocationType, DoorType from BaseClasses import LocationType, DoorType
@@ -334,10 +335,11 @@ class CustomSettings(object):
def load_yaml(path): def load_yaml(path):
try: try:
if urllib.parse.urlparse(path).scheme: return yaml.load(path, Loader=yaml.SafeLoader)
return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) except yaml.YAMLError as exc:
with open(path, 'r', encoding='utf-8') as f: if os.path.exists(Path(path)):
with open(path, "r", encoding="utf-8") as f:
return yaml.load(f, Loader=yaml.SafeLoader) return yaml.load(f, Loader=yaml.SafeLoader)
except Exception as e: elif urllib.parse.urlparse(path).scheme in ['http', 'https']:
raise Exception(f'Failed to read customizer file: {e}') return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader)

View File

@@ -1,5 +1,7 @@
import argparse import argparse
import RaceRandom as random import RaceRandom as random
import os
from pathlib import Path
import urllib.request import urllib.request
import urllib.parse import urllib.parse
@@ -8,12 +10,13 @@ import yaml
def get_weights(path): def get_weights(path):
try: try:
if urllib.parse.urlparse(path).scheme: return yaml.load(path, Loader=yaml.SafeLoader)
return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) except yaml.YAMLError as exc:
with open(path, 'r', encoding='utf-8') as f: if os.path.exists(Path(path)):
with open(path, "r", encoding="utf-8") as f:
return yaml.load(f, Loader=yaml.SafeLoader) return yaml.load(f, Loader=yaml.SafeLoader)
except Exception as e: elif urllib.parse.urlparse(path).scheme in ['http', 'https']:
raise Exception(f'Failed to read weights file: {e}') return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader)
def roll_settings(weights): def roll_settings(weights):