From 1b936fa028fc5e340af69c135192fe53f8fdd9f8 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Tue, 6 Jan 2015 10:05:58 +0100 Subject: [PATCH] Made question parser more unicode friendly --- question.py | 6 +++--- seopardy.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/question.py b/question.py index dab5d0e..358ff80 100644 --- a/question.py +++ b/question.py @@ -105,7 +105,7 @@ class Questions(object): # read sections basedir = os.path.dirname(filename) for n, sec_filename in enumerate(ysrc["Sections"], 1): - if type(sec_filename) != str: + if type(sec_filename) not in (unicode, str): self._gen_error(filename, "Section element %d is not a string (type %s found)" % (n, type(sec_filename))) fpath = os.path.join(basedir, sec_filename) @@ -129,8 +129,8 @@ class Questions(object): self._gen_error(filename, "Question %d from section %d (%s) is missing one of the keywords Question, Answer or Type" % (j, i, sec["Section"])) # check wether the question is a string (else we'll get display errors) - if type(q["Question"]) != str: - self._gen_error(filename, "Question %d from section %d (%s) needs to have a string as question (put the Question in \"\")" % (j, i, sec["Section"])) + if type(q["Question"]) not in (str, unicode): + self._gen_error(filename, "Question %d from section %d (%s) needs to have a string as question (type found was '%s', maybe put the Question in \"\")" % (j, i, sec["Section"], type(q["Question"]))) # check for keys we do not know diff --git a/seopardy.py b/seopardy.py index 809573b..5864bf1 100755 --- a/seopardy.py +++ b/seopardy.py @@ -31,7 +31,7 @@ if __name__ == '__main__': try: questions = Questions(args.questions, appendPath=not args.no_cwd, verbose=args.verbose) except QuestionException as e: - print(str(e), file=sys.stderr) + print(e.message, file=sys.stderr) sys.exit(1) # start gui @@ -43,10 +43,10 @@ if __name__ == '__main__': try: config = yaml.safe_load(open(args.conf)) except IOError as e: - print("Error: Could not load config: %s" % (str(e),), file=sys.stderr) + print("Error: Could not load config: %s" % (e,), file=sys.stderr) sys.exit(1) except yaml.scanner.ScannerError as e: - print("Error: Could not parse config file: %s" % (str(e),), file=sys.stderr) + print("Error: Could not parse config file: %s" % (e,), file=sys.stderr) sys.exit(1) check_config(config) @@ -58,7 +58,7 @@ if __name__ == '__main__': try: sstream = open(args.gamestate, "r") except IOError as e: - print("Error: Could not load gamestate: %s" % (str(e),), file=sys.stderr) + print("Error: Could not load gamestate: %s" % (e,), file=sys.stderr) sys.exit(1) gamestate = GameState.load(sstream, config["savedir"]) else: