fix encoding

This commit is contained in:
virusdefender 2018-03-26 07:07:36 +08:00
parent cee8831690
commit dca5db7348
8 changed files with 21 additions and 7 deletions

View File

@ -14,7 +14,6 @@ services:
- /tmp
- /judger_run:exec,mode=777
- /spj:exec,mode=777
- /dev/shm:mode=777
volumes:
- $PWD/tests/test_case:/test_case:ro
- $PWD/log:/log

1
server/.python-version Normal file
View File

@ -0,0 +1 @@
3.6.2

View File

@ -34,7 +34,7 @@ class Compiler(object):
if result["result"] != _judger.RESULT_SUCCESS:
if os.path.exists(compiler_out):
with open(compiler_out) as f:
with open(compiler_out, encoding="utf-8") as f:
error = f.read().strip()
os.remove(compiler_out)
if error:

View File

@ -56,7 +56,7 @@ class JudgeClient(object):
def _compare_output(self, test_case_file_id):
user_output_file = os.path.join(self._submission_dir, str(test_case_file_id) + ".out")
with open(user_output_file, "r") as f:
with open(user_output_file, "r", encoding="utf-8") as f:
content = f.read()
output_md5 = hashlib.md5(content.rstrip().encode("utf-8")).hexdigest()
result = output_md5 == self._get_test_case_file_info(test_case_file_id)["stripped_output_md5"]
@ -141,7 +141,7 @@ class JudgeClient(object):
if self._output:
try:
with open(user_output_file, "r") as f:
with open(user_output_file, "r", encoding="utf-8") as f:
run_result["output"] = f.read()
except Exception:
pass

View File

@ -66,7 +66,7 @@ class JudgeServer:
src_path = os.path.join(submission_dir, compile_config["src_name"])
# write source code into file
with open(src_path, "w") as f:
with open(src_path, "w", encoding="utf-8") as f:
f.write(src)
# compile source code, return exe file path
@ -75,7 +75,7 @@ class JudgeServer:
output_dir=submission_dir)
else:
exe_path = os.path.join(submission_dir, run_config["exe_name"])
with open(exe_path, "w") as f:
with open(exe_path, "w", encoding="utf-8") as f:
f.write(src)
judge_client = JudgeClient(run_config=language_config["run"],
@ -100,7 +100,7 @@ class JudgeServer:
# if spj source code not found, then write it into file
if not os.path.exists(spj_src_path):
with open(spj_src_path, "w") as f:
with open(spj_src_path, "w", encoding="utf-8") as f:
f.write(src)
try:
Compiler().compile(compile_config=spj_compile_config,

View File

@ -0,0 +1 @@
你好,世界

View File

@ -0,0 +1 @@
你好,世界

View File

@ -0,0 +1,12 @@
{
"spj": false,
"test_cases": {
"1": {
"stripped_output_md5": "dbefd3ada018615b35588a01e216ae6e",
"input_size": 16,
"output_size": 16,
"input_name": "1.in",
"output_name": "1.out"
}
}
}