Made question parser more unicode friendly

This commit is contained in:
Sebastian Lohff 2015-01-06 10:05:58 +01:00
parent 936c98da86
commit 1b936fa028
2 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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: