Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:time_limit字段值在1.2版本中解析出错 #331

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_regular_user_validate_contest_password(self):
self.create_user("test", "test123")
url = self.reverse("contest_password_api")
resp = self.client.post(url, {"contest_id": self.contest.id, "password": "error_password"})
self.assertDictEqual(resp.data, {"error": "error", "data": "Wrong password"})
self.assertDictEqual(resp.data, {"error": "error", "data": "Wrong password or password expired"})

resp = self.client.post(url, {"contest_id": self.contest.id, "password": DEFAULT_CONTEST_DATA["password"]})
self.assertSuccess(resp)
Expand Down
12 changes: 8 additions & 4 deletions fps/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def __init__(self, fps_path=None, string_data=None):
self._ertree = ET.fromstring(string_data).getroot()
else:
raise ValueError("You must tell me the file path or directly give me the data for the file")
version = self._etree.attrib.get("version", "No Version")
if version not in ["1.1", "1.2"]:
raise ValueError("Unsupported version '" + version + "'")
self.version = self._etree.attrib.get("version", "No Version")
if self.version not in ["1.1", "1.2"]:
raise ValueError("Unsupported version '" + self.version + "'")

@property
def etree(self):
Expand Down Expand Up @@ -52,7 +52,11 @@ def _parse_one_problem(self, node):
if unit not in ["s", "ms"]:
raise ValueError("Invalid time limit unit")
problem["time_limit"]["unit"] = item.attrib.get("unit", "s")
value = int(item.text)
value = 0
if self.version != "1.1":
value = float(item.text)
else:
value = int(item.text)
if value <= 0:
raise ValueError("Invalid time limit value")
problem["time_limit"]["value"] = value
Expand Down
5 changes: 2 additions & 3 deletions problem/views/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import hashlib
import json
import os
import shutil
import tempfile
import zipfile
from wsgiref.util import FileWrapper
Expand Down Expand Up @@ -676,10 +675,10 @@ def post(self, request):
with tempfile.NamedTemporaryFile("wb") as tf:
for chunk in file.chunks(4096):
tf.file.write(chunk)

tf.file.flush()
os.fsync(tf.file)

problems = FPSParser(tf.name).parse()
else:
return self.error("Parse upload file error")
Expand Down
2 changes: 1 addition & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class Difficulty(Choices):
HIGH = "High"


CONTEST_PASSWORD_SESSION_KEY = "contest_password"
CONTEST_PASSWORD_SESSION_KEY = "contest_password"