@@ -234,6 +234,23 @@ def get_problems(categories):
234234 return sorted (problems , key = lambda p : p ['id' ])
235235
236236
237+ def _split (s ):
238+ if isinstance (s , list ):
239+ lines = []
240+ for element in s :
241+ lines .extend (_split (element ))
242+ return lines
243+
244+ # Replace all \r\n to \n and all \r (alone) to \n
245+ s = s .replace ('\r \n ' , '\n ' ).replace ('\r ' , '\n ' ).replace ('\0 ' , '\n ' )
246+ # str.split has an disadvantage that ''.split('\n') results in [''], but what we want
247+ # is []. This small function returns [] if `s` is a blank string, that is, containing no
248+ # characters other than whitespaces.
249+ if s .strip () == '' :
250+ return []
251+ return s .split ('\n ' )
252+
253+
237254def get_problem (slug ):
238255 assert is_login ()
239256 headers = _make_headers ()
@@ -277,23 +294,14 @@ def get_problem(slug):
277294 for t in json .loads (q ['codeDefinition' ]):
278295 problem ['templates' ][t ['value' ]] = _break_code_lines (t ['defaultCode' ])
279296 problem ['testable' ] = q ['enableRunCode' ]
280- problem ['testcase' ] = q ['sampleTestCase' ]
297+ problem ['testcase' ] = _split ( q ['sampleTestCase' ])
281298 stats = json .loads (q ['stats' ])
282299 problem ['total_accepted' ] = stats ['totalAccepted' ]
283300 problem ['total_submission' ] = stats ['totalSubmission' ]
284301 problem ['ac_rate' ] = stats ['acRate' ]
285302 return problem
286303
287304
288- def _split (s ):
289- # str.split has an disadvantage that ''.split('\n') results in [''], but what we want
290- # is []. This small function returns [] if `s` is a blank string, that is, containing no
291- # characters other than whitespaces.
292- if s .strip () == '' :
293- return []
294- return s .split ('\n ' )
295-
296-
297305def _check_result (submission_id ):
298306 global task_progress
299307 if _in_task ():
@@ -333,7 +341,7 @@ def _check_result(submission_id):
333341 'testcase' : _split (r .get ('input' , r .get ('last_testcase' , '' ))),
334342 'passed' : r .get ('total_correct' ) or 0 ,
335343 'total' : r .get ('total_testcases' ) or 0 ,
336- 'error' : [v for k , v in r .items () if 'error' in k and v ]
344+ 'error' : _split ( [v for k , v in r .items () if 'error' in k and v ])
337345 }
338346
339347 # the keys differs between the result of testing the code and submitting it
0 commit comments