upgrade to python3;add some validator examples
This commit is contained in:
@@ -23,20 +23,23 @@ class InternalJudge:
|
||||
return self.compare_file(tin, tout, result, self.allowpe)
|
||||
|
||||
def compare_file(self, input, output, result, allowpe):
|
||||
fo = file(output, 'rb'); fr = file(result, 'rb')
|
||||
with open(output, 'rb') as fo, open(result, 'rb') as fr:
|
||||
|
||||
if not allowpe:
|
||||
r = 'AC'
|
||||
while r == 'AC':
|
||||
so = fo.read(8192); sr = fr.read(8192)
|
||||
if so == '' and sr == '': break
|
||||
if so != sr: r = 'WA'
|
||||
else:
|
||||
so = fo.read(); sr = fr.read()
|
||||
r = self.compare_string(so, sr)
|
||||
|
||||
fo.close(); fr.close()
|
||||
return r
|
||||
if not allowpe:
|
||||
r = 'AC'
|
||||
while r == 'AC':
|
||||
so = fo.read(8192)
|
||||
sr = fr.read(8192)
|
||||
if so == b'' and sr == b'':
|
||||
break
|
||||
if so != sr:
|
||||
r = 'WA'
|
||||
else:
|
||||
so = fo.read()
|
||||
sr = fr.read()
|
||||
r = self.compare_string(so.decode('utf-8', errors='ignore'),
|
||||
sr.decode('utf-8', errors='ignore'))
|
||||
return r
|
||||
|
||||
def compare_string(self, output, result):
|
||||
if output == result: return 'AC'
|
||||
@@ -76,10 +79,10 @@ class ExternalJudge:
|
||||
os.makedirs(datadir)
|
||||
self.comparecmd = tester.comparecmd
|
||||
self.codefile = os.path.abspath(os.path.join(datadir, tester.source))
|
||||
f = file(self.codefile, 'w')
|
||||
f.write(string.replace(vcode, '\r\n', '\n'))
|
||||
if len(vcode) > 0 and vcode[-1] != '\n': f.write('\n')
|
||||
f.close()
|
||||
with open(self.codefile, 'w') as f:
|
||||
f.write(string.replace(vcode, '\r\n', '\n'))
|
||||
if len(vcode) > 0 and vcode[-1] != '\n':
|
||||
f.write('\n')
|
||||
|
||||
self.logger.debug("Save validator code as %s" % self.codefile)
|
||||
|
||||
@@ -119,7 +122,7 @@ class ExternalJudge:
|
||||
|
||||
if rundir: os.chdir(rundir)
|
||||
os.execv(cmd[0], cmd)
|
||||
print 'WA'
|
||||
print('WA')
|
||||
|
||||
remaintime = self.config.judgescript_wait
|
||||
pid1 = 0
|
||||
@@ -133,13 +136,12 @@ class ExternalJudge:
|
||||
while pid1 == 0:
|
||||
try:
|
||||
os.kill(pid, 9)
|
||||
except os.OSError, e:
|
||||
except OSError:
|
||||
pass
|
||||
pid1, status = os.waitpid(pid, os.WNOHANG)
|
||||
|
||||
f = file(rfile, 'r')
|
||||
ret = string.strip(f.readline())
|
||||
f.close()
|
||||
with open(rfile, 'r') as f:
|
||||
ret = f.readline().strip()
|
||||
if ret != 'AC' and ret != 'PE': ret = 'WA'
|
||||
return ret
|
||||
|
||||
@@ -268,7 +270,7 @@ public class Main {
|
||||
def testPython(self):
|
||||
code = """#!/usr/bin/env python
|
||||
|
||||
print 'AC'
|
||||
print('AC')
|
||||
"""
|
||||
self.j = ExternalJudge('p1', 'python-2.5', code)
|
||||
x = self.j.judge('s1', 't1', self.tin.name, self.tout.name, self.rst.name, self.err.name)
|
||||
|
||||
Reference in New Issue
Block a user