comparison upreckon/problem.py @ 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
comparison
equal deleted inserted replaced
233:54cdc583ab77 240:2798cbebd83a
140 id = str(case.id) 140 id = str(case.id)
141 if case.isdummy: 141 if case.isdummy:
142 id = 'sample ' + id 142 id = 'sample ' + id
143 say('%*s: ' % (prob.cache.padoutput, id), end='') 143 say('%*s: ' % (prob.cache.padoutput, id), end='')
144 sys.stdout.flush() 144 sys.stdout.flush()
145 comment = ''.encode() 145 comment = ''
146 try: 146 try:
147 if prob.config.kind != 'outonly': 147 if prob.config.kind != 'outonly':
148 granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush())) 148 granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush()))
149 else: 149 else:
150 granted = case(lambda: None) 150 granted = case(lambda: None)
192 # verdict = 'unknown error [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1]) 192 # verdict = 'unknown error [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1])
193 else: 193 else:
194 try: 194 try:
195 granted, correct, comment = granted 195 granted, correct, comment = granted
196 except TypeError: 196 except TypeError:
197 comment = ''.encode()
198 correct = granted >= 1 197 correct = granted >= 1
199 if correct: 198 if correct:
200 contexts[-1].case_correct() 199 contexts[-1].case_correct()
201 prob.testcases.send(True) 200 prob.testcases.send(True)
202 verdict = 'OK' 201 verdict = 'OK'
203 else: 202 else:
204 verdict = 'partly correct' 203 verdict = 'partly correct'
205 granted *= case.points 204 granted *= case.points
206 if comment: 205 if comment:
207 say('%g/%g, %s (' % (granted, case.points, verdict), end='') 206 say('%g/%g, %s (' % (granted, case.points, verdict), end='')
208 sys.stdout.flush() 207 if isinstance(comment, type(''.encode())) and hasattr(sys.stdout, 'buffer'):
209 try: 208 sys.stdout.flush()
210 sys.stdout.buffer.write(comment) 209 sys.stdout.buffer.write(comment)
211 except AttributeError: 210 else:
212 sys.stdout.write(comment) 211 say(comment, end='')
213 say(')') 212 say(')')
214 else: 213 else:
215 say('%g/%g, %s' % (granted, case.points, verdict)) 214 say('%g/%g, %s' % (granted, case.points, verdict))
216 contexts[-1].case_end() 215 contexts[-1].case_end()
217 contexts[-1].score(granted, case.points) 216 contexts[-1].score(granted, case.points)