# HG changeset patch # User Oleg Oshmyan # Date 1355186880 -7200 # Node ID 2798cbebd83a02d849bf00c79420102549740ddd # Parent 54cdc583ab77a6a2063822070c535a4908aca0b4 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. diff -r 54cdc583ab77 -r 2798cbebd83a upreckon/problem.py --- 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))