diff upreckon/problem.py @ 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 c03a8113685d
children 54cdc583ab77
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