From 99577d9e4c2398d84ee9facb13521d6aa1d80e6b Mon Sep 17 00:00:00 2001 From: Bonta-kun <40473493+Bonta0@users.noreply.github.com> Date: Mon, 6 Jan 2020 20:14:16 +0100 Subject: [PATCH] Mystery: safer strip --- Mystery.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Mystery.py b/Mystery.py index 298b9217..9d7755ea 100644 --- a/Mystery.py +++ b/Mystery.py @@ -8,15 +8,18 @@ from EntranceRandomizer import parse_arguments from Main import main as ERmain def parse_yaml(txt): + def strip(s): + s = s.strip() + return '' if not s else s.strip('"') if s[0] == '"' else s.strip("'") if s[0] == "'" else s ret = {} indents = {len(txt) - len(txt.lstrip(' ')): ret} for line in txt.splitlines(): if not line: continue name, val = line.split(':', 1) - val = val.strip() + val = strip(val) spaces = len(name) - len(name.lstrip(' ')) - name = name.strip() + name = strip(name) if val: indents[spaces][name] = val else: @@ -114,7 +117,7 @@ def roll_settings(weights): return root[option] if not root[option]: return None - return random.choices(list(root[option].keys()), weights=list(map(int,root[option].values())))[0].replace('"','').replace("'",'') + return random.choices(list(root[option].keys()), weights=list(map(int,root[option].values())))[0] ret = argparse.Namespace()