From c97b57e95acb597df844473ec11917b29f01c40e Mon Sep 17 00:00:00 2001 From: virusdefender Date: Tue, 4 Oct 2016 14:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E5=AF=B9special=20judge?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- judge_client.py | 10 +++++++--- service.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/judge_client.py b/judge_client.py index c0f0ccb..696aa04 100644 --- a/judge_client.py +++ b/judge_client.py @@ -38,6 +38,10 @@ class JudgeClient(object): self._spj_version = spj_version self._spj_config = spj_config + if self._spj_version and self._spj_config: + self._spj_exe = os.path.join(self._test_case_dir, self._spj_config["exe_name"].format(spj_version=self._spj_version)) + if not os.path.exists(self._spj_exe): + raise JudgeClientError("spj exe not found") def _load_test_case_info(self): try: @@ -62,9 +66,9 @@ class JudgeClient(object): return output_md5, output_md5 == self._test_case_info["test_cases"][str(test_case_file_id)]["striped_output_md5"] def _spj(self, in_file_path, user_out_file_path): - command = self._spj_config["command"].format(exe_path=os.path.join(self._test_case_dir, - self._spj_config["exe_name"].format(spj_version=self._spj_version)), - in_file_path=in_file_path, user_out_file_path=user_out_file_path).split(" ") + command = self._spj_config["command"].format(exe_path=self._spj_exe, + in_file_path=in_file_path, + user_out_file_path=user_out_file_path).split(" ") result = _judger.run(max_cpu_time=self._max_cpu_time * 3, max_real_time=self._max_cpu_time * 9, max_memory=self._max_memory * 3, diff --git a/service.py b/service.py index a0fad45..d6e10a9 100644 --- a/service.py +++ b/service.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import os import json import requests +import hashlib from exception import JudgeServiceError from utils import server_info, get_token, logger @@ -29,7 +30,7 @@ class JudgeService(object): def _request(self, data): try: r = requests.post(self.service_discovery_url, data=json.dumps(data), - headers={"X-JUDGE-SERVER-TOKEN": get_token()}, timeout=5).json() + headers={"X-JUDGE-SERVER-TOKEN": hashlib.sha256(get_token()).hexdigest()}, timeout=5).json() except Exception as e: logger.exception(e) raise JudgeServiceError(e.message)