changeset 232:f94f9724c543

Switched from str to bytes for external validator output
author Oleg Oshmyan <chortos@inbox.lv>
date Fri, 29 Jun 2012 03:32:49 +0300
parents 928a6091454c
children 54cdc583ab77
files upreckon/problem.py upreckon/testcases.py
diffstat 2 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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 <chortos@inbox.lv>
+# Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv>
 
 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
--- 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 <chortos@inbox.lv>
+# Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv>
 
 # 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: