# HG changeset patch # User Oleg Oshmyan # Date 1340929969 -10800 # Node ID f94f9724c543f4f99f91550890258745a6b41bb5 # Parent 928a6091454c7fefdb40d45d6da27e303c82a750 Switched from str to bytes for external validator output diff -r 928a6091454c -r f94f9724c543 upreckon/problem.py --- a/upreckon/problem.py Wed Jun 06 20:41:44 2012 +0100 +++ b/upreckon/problem.py Fri Jun 29 03:32:49 2012 +0300 @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2011 Chortos-2 +# Copyright (c) 2010-2012 Chortos-2 from __future__ import division, with_statement @@ -142,6 +142,7 @@ id = 'sample ' + id say('%*s: ' % (prob.cache.padoutput, id), end='') sys.stdout.flush() + comment = ''.encode() try: if prob.config.kind != 'outonly': granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush())) @@ -158,11 +159,10 @@ except MemoryLimitExceeded: verdict = 'memory limit exceeded' except WrongAnswer: + verdict = 'wrong answer' e = sys.exc_info()[1] if e.comment: - verdict = 'wrong answer (%s)' % e.comment - else: - verdict = 'wrong answer' + comment = e.comment except NonZeroExitCode: e = sys.exc_info()[1] if e.exitcode < 0: @@ -194,19 +194,22 @@ try: granted, correct, comment = granted except TypeError: - comment = '' + comment = ''.encode() correct = granted >= 1 - else: - if comment: - comment = ' (%s)' % comment if correct: contexts[-1].case_correct() prob.testcases.send(True) - verdict = 'OK' + comment + verdict = 'OK' else: - verdict = 'partly correct' + comment + verdict = 'partly correct' granted *= case.points - say('%g/%g, %s' % (granted, case.points, verdict)) + if comment: + say('%g/%g, %s (' % (granted, case.points, verdict), end='') + sys.stdout.flush() + sys.stdout.buffer.write(comment) + say(')') + else: + say('%g/%g, %s' % (granted, case.points, verdict)) contexts[-1].case_end() contexts[-1].score(granted, case.points) weighted = contexts[0].real * prob.config.taskweight / contexts[0].max if contexts[0].max else 0 diff -r 928a6091454c -r f94f9724c543 upreckon/testcases.py --- a/upreckon/testcases.py Wed Jun 06 20:41:44 2012 +0100 +++ b/upreckon/testcases.py Fri Jun 29 03:32:49 2012 +0300 @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2011 Chortos-2 +# Copyright (c) 2010-2012 Chortos-2 # TODO: copy the ansfile if not options.erase even if no validator is used @@ -227,12 +227,12 @@ case.open_outfile() case.outfile.copy(case.problem.config.ansname) try: - case.process = Popen(case.validator, stdin=devnull, stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=-1) + case.process = Popen(case.validator, stdin=devnull, stdout=PIPE, stderr=STDOUT, bufsize=-1) except OSError: raise CannotStartValidator(sys.exc_info()[1]) with signal_ignorer: comment = case.process.communicate()[0].strip() - match = re.match(r'(?i)(?:ok|(?:(?:in)?correct|wrong)(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)', comment) + match = re.match(r'(?i)(?:ok|(?:(?:in)?correct|wrong)(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)'.encode('ascii'), comment) if match: comment = comment[match.end():] if not case.problem.config.maxexitcode: