changeset 240:2798cbebd83a

Re-allowed callable output validators to give comments as Unicode strings At the same time: * removed an unnecessary sys.stdout.flush() on Python 2, * removed an unnecessary variable re-initialization.
author Oleg Oshmyan <chortos@inbox.lv>
date Tue, 11 Dec 2012 02:48:00 +0200
parents 54cdc583ab77
children 478d4217fe03 cf7dd3f46e89
files upreckon/problem.py
diffstat 1 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/upreckon/problem.py	Sat Oct 20 21:03:44 2012 +0100
+++ b/upreckon/problem.py	Tue Dec 11 02:48:00 2012 +0200
@@ -142,7 +142,7 @@
 					id = 'sample ' + id
 				say('%*s: ' % (prob.cache.padoutput, id), end='')
 				sys.stdout.flush()
-				comment = ''.encode()
+				comment = ''
 				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()))
@@ -194,7 +194,6 @@
 					try:
 						granted, correct, comment = granted
 					except TypeError:
-						comment = ''.encode()
 						correct = granted >= 1
 					if correct:
 						contexts[-1].case_correct()
@@ -205,11 +204,11 @@
 					granted *= case.points
 				if comment:
 					say('%g/%g, %s (' % (granted, case.points, verdict), end='')
-					sys.stdout.flush()
-					try:
+					if isinstance(comment, type(''.encode())) and hasattr(sys.stdout, 'buffer'):
+						sys.stdout.flush()
 						sys.stdout.buffer.write(comment)
-					except AttributeError:
-						sys.stdout.write(comment)
+					else:
+						say(comment, end='')
 					say(')')
 				else:
 					say('%g/%g, %s' % (granted, case.points, verdict))