From 38da4066fb7c628175540e6925100547ddffd3b8 Mon Sep 17 00:00:00 2001 From: prandla Date: Tue, 22 Jul 2025 08:35:52 +0300 Subject: [PATCH] clean up some imports * Remove unneeded import attempts from "tornado4". From what I can tell, this was only ever useful when using system packages on ubuntu 20.04. We don't support installation using system packages anymore (and ubuntu 20.04 is EOL). * Remove misleading comment about monkey-patching the DB connection string in the test suite. We don't monkey-patch it anymore (instead we assume someone else fixed it and assert that it's correct). --- cms/io/web_service.py | 7 +-- cms/server/admin/handlers/base.py | 15 +++--- .../admin/handlers/contestannouncement.py | 7 +-- cms/server/admin/handlers/contestquestion.py | 9 ++-- cms/server/admin/handlers/contestuser.py | 13 ++--- cms/server/admin/handlers/dataset.py | 13 ++--- cms/server/admin/handlers/task.py | 9 ++-- cms/server/contest/handlers/base.py | 7 +-- cms/server/contest/handlers/communication.py | 11 ++-- cms/server/contest/handlers/contest.py | 9 ++-- cms/server/contest/handlers/main.py | 39 +++++++------- cms/server/contest/handlers/task.py | 21 ++++---- cms/server/contest/handlers/tasksubmission.py | 41 +++++++------- cms/server/contest/handlers/taskusertest.py | 53 +++++++++---------- cms/server/util.py | 8 +-- .../unit_tests/cmscontrib/AddAdminTest.py | 1 - .../cmscontrib/AddParticipationTest.py | 1 - .../unit_tests/cmscontrib/AddStatementTest.py | 1 - .../cmscontrib/AddSubmissionTest.py | 1 - .../unit_tests/cmscontrib/DumpExporterTest.py | 1 - .../unit_tests/cmscontrib/DumpImporterTest.py | 1 - .../cmscontrib/ImportContestTest.py | 1 - .../cmscontrib/ImportDatasetTest.py | 1 - .../unit_tests/cmscontrib/ImportTaskTest.py | 1 - .../unit_tests/cmscontrib/ImportTeamTest.py | 1 - .../unit_tests/cmscontrib/ImportUserTest.py | 1 - cmstestsuite/unit_tests/db/filecacher_test.py | 1 - .../unit_tests/grading/ParameterTypesTest.py | 5 +- .../unit_tests/grading/scoring_test.py | 1 - .../server/contest/authentication_test.py | 1 - .../server/contest/communication_test.py | 1 - .../server/contest/printing_test.py | 1 - .../server/contest/submission/check_test.py | 1 - .../server/contest/submission/utils_test.py | 1 - .../contest/submission/workflow_test.py | 1 - .../server/contest/tokening_test.py | 1 - .../unit_tests/service/ProxyServiceTest.py | 1 - .../unit_tests/service/ScoringServiceTest.py | 1 - .../unit_tests/service/esoperations_test.py | 1 - .../service/scoringoperations_test.py | 1 - 40 files changed, 108 insertions(+), 183 deletions(-) diff --git a/cms/io/web_service.py b/cms/io/web_service.py index c402475cb1..a6032ee641 100644 --- a/cms/io/web_service.py +++ b/cms/io/web_service.py @@ -28,10 +28,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.wsgi as tornado_wsgi -except ImportError: - import tornado.wsgi as tornado_wsgi +import tornado.wsgi from gevent.pywsgi import WSGIServer from werkzeug.contrib.fixers import ProxyFix from werkzeug.middleware.dispatcher import DispatcherMiddleware @@ -71,7 +68,7 @@ def __init__( is_proxy_used = parameters.pop('is_proxy_used', None) num_proxies_used = parameters.pop('num_proxies_used', None) - self.wsgi_app = tornado_wsgi.WSGIApplication(handlers, **parameters) + self.wsgi_app = tornado.wsgi.WSGIApplication(handlers, **parameters) self.wsgi_app.service = self for entry in static_files: diff --git a/cms/server/admin/handlers/base.py b/cms/server/admin/handlers/base.py index ba5a3ec473..25af1222c8 100644 --- a/cms/server/admin/handlers/base.py +++ b/cms/server/admin/handlers/base.py @@ -46,10 +46,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Query, subqueryload @@ -81,7 +78,7 @@ def argument_reader(func: Callable[[str], typing.Any], empty: object = None): """ def helper( - self: tornado_web.RequestHandler, dest: dict, name: str, empty: object = empty + self: tornado.web.RequestHandler, dest: dict, name: str, empty: object = empty ): """Read the argument called "name" and save it in "dest". @@ -194,7 +191,7 @@ def decorator( """ @wraps(func) - @tornado_web.authenticated + @tornado.web.authenticated def newfunc(self: _T, *args: _P.args, **kwargs: _P.kwargs): """Check if the permission is present before calling the function. @@ -213,7 +210,7 @@ def newfunc(self: _T, *args: _P.args, **kwargs: _P.kwargs): # the current user id. return func(self, *args, **kwargs) else: - raise tornado_web.HTTPError(403, "Admin is not authorized") + raise tornado.web.HTTPError(403, "Admin is not authorized") return newfunc @@ -302,7 +299,7 @@ def safe_get_item( session = self.sql_session entity = cls.get_from_id(ident, session) if entity is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) return entity def prepare(self): @@ -354,7 +351,7 @@ def render_params(self) -> dict: def write_error(self, status_code, **kwargs): if "exc_info" in kwargs and \ - kwargs["exc_info"][0] != tornado_web.HTTPError: + kwargs["exc_info"][0] != tornado.web.HTTPError: exc_info = kwargs["exc_info"] logger.error( "Uncaught exception (%r) while processing a request: %s", diff --git a/cms/server/admin/handlers/contestannouncement.py b/cms/server/admin/handlers/contestannouncement.py index 34e517a5f7..658d42845d 100644 --- a/cms/server/admin/handlers/contestannouncement.py +++ b/cms/server/admin/handlers/contestannouncement.py @@ -33,10 +33,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.db import Contest, Announcement from cmscommon.datetime import make_datetime @@ -77,7 +74,7 @@ def delete(self, contest_id: str, ann_id: str): # Protect against URLs providing incompatible parameters. if self.contest is not ann.contest: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.sql_session.delete(ann) self.try_commit() diff --git a/cms/server/admin/handlers/contestquestion.py b/cms/server/admin/handlers/contestquestion.py index 71cd7624e7..42583581c3 100644 --- a/cms/server/admin/handlers/contestquestion.py +++ b/cms/server/admin/handlers/contestquestion.py @@ -35,10 +35,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.db import Contest, Question, Participation from cmscommon.datetime import make_datetime @@ -88,7 +85,7 @@ def post(self, contest_id, question_id): # Protect against URLs providing incompatible parameters. if self.contest is not question.participation.contest: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.process_question(question) self.redirect(ref) @@ -148,7 +145,7 @@ class QuestionClaimHandler(QuestionActionHandler): def process_question(self, question): # Can claim/unclaim only a question not ignored or answered. if question.ignored or question.reply_timestamp is not None: - raise tornado_web.HTTPError(405) + raise tornado.web.HTTPError(405) should_claim = self.get_argument("claim", "no") == "yes" diff --git a/cms/server/admin/handlers/contestuser.py b/cms/server/admin/handlers/contestuser.py index b940a316d5..d3d0e3493a 100644 --- a/cms/server/admin/handlers/contestuser.py +++ b/cms/server/admin/handlers/contestuser.py @@ -38,10 +38,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.db import Contest, Message, Participation, Submission, User, Team from cmscommon.datetime import make_datetime @@ -113,7 +110,7 @@ def get(self, contest_id, user_id): ) # Check that the participation is valid. if participation is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission_query = self.sql_session.query(Submission)\ .filter(Submission.participation == participation) @@ -193,7 +190,7 @@ def get(self, contest_id, user_id): # Check that the participation is valid. if participation is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission_query = self.sql_session.query(Submission)\ .filter(Submission.participation == participation) @@ -220,7 +217,7 @@ def post(self, contest_id, user_id): # Check that the participation is valid. if participation is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) try: attrs = participation.get_attrs() @@ -281,7 +278,7 @@ def post(self, contest_id, user_id): # check that the participation is valid if participation is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) message = Message(make_datetime(), self.get_argument("message_subject", ""), diff --git a/cms/server/admin/handlers/dataset.py b/cms/server/admin/handlers/dataset.py index 6a11184fc4..1a0b153e0f 100644 --- a/cms/server/admin/handlers/dataset.py +++ b/cms/server/admin/handlers/dataset.py @@ -39,10 +39,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.db import Dataset, Manager, Message, Participation, \ Session, Submission, Task, Testcase @@ -102,7 +99,7 @@ def get(self, dataset_id_to_copy): self.safe_get_item(Dataset, dataset_id_to_copy) description = "Copy of %s" % original_dataset.description except ValueError: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.r_params = self.render_params() self.r_params["task"] = task @@ -125,7 +122,7 @@ def post(self, dataset_id_to_copy): original_dataset = \ self.safe_get_item(Dataset, dataset_id_to_copy) except ValueError: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) try: attrs = dict() @@ -406,7 +403,7 @@ def delete(self, dataset_id, manager_id): # Protect against URLs providing incompatible parameters. if manager.dataset is not dataset: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task_id = dataset.task_id @@ -562,7 +559,7 @@ def delete(self, dataset_id, testcase_id): # Protect against URLs providing incompatible parameters. if dataset is not testcase.dataset: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task_id = testcase.dataset.task_id diff --git a/cms/server/admin/handlers/task.py b/cms/server/admin/handlers/task.py index 20c2186eb2..21308d1f02 100644 --- a/cms/server/admin/handlers/task.py +++ b/cms/server/admin/handlers/task.py @@ -36,10 +36,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.db import Attachment, Dataset, Session, Statement, Submission, Task from cmscommon.datetime import make_datetime @@ -296,7 +293,7 @@ def delete(self, task_id, statement_id): # Protect against URLs providing incompatible parameters. if task is not statement.task: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.sql_session.delete(statement) self.try_commit() @@ -368,7 +365,7 @@ def delete(self, task_id, attachment_id): # Protect against URLs providing incompatible parameters. if attachment.task is not task: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.sql_session.delete(attachment) self.try_commit() diff --git a/cms/server/contest/handlers/base.py b/cms/server/contest/handlers/base.py index 02b8bb8b7a..ebc29f8e6a 100644 --- a/cms/server/contest/handlers/base.py +++ b/cms/server/contest/handlers/base.py @@ -42,10 +42,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from werkzeug.datastructures import LanguageAccept from werkzeug.http import parse_accept_header @@ -159,7 +156,7 @@ def render_params(self) -> dict: def write_error(self, status_code, **kwargs): if "exc_info" in kwargs and \ - kwargs["exc_info"][0] != tornado_web.HTTPError: + kwargs["exc_info"][0] != tornado.web.HTTPError: exc_info = kwargs["exc_info"] logger.error( "Uncaught exception (%r) while processing a request: %s", diff --git a/cms/server/contest/handlers/communication.py b/cms/server/contest/handlers/communication.py index 572b13be64..a45b5f094d 100644 --- a/cms/server/contest/handlers/communication.py +++ b/cms/server/contest/handlers/communication.py @@ -36,10 +36,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.server import multi_contest from cms.server.contest.communication import accept_question, \ @@ -60,7 +57,7 @@ class CommunicationHandler(ContestHandler): and the contest managers.. """ - @tornado_web.authenticated + @tornado.web.authenticated @multi_contest def get(self): self.render("communication.html", **self.r_params) @@ -70,7 +67,7 @@ class QuestionHandler(ContestHandler): """Called when the user submits a question. """ - @tornado_web.authenticated + @tornado.web.authenticated @multi_contest def post(self): try: @@ -79,7 +76,7 @@ def post(self): self.get_argument("question_text", "")) self.sql_session.commit() except QuestionsNotAllowed: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) except UnacceptableQuestion as e: self.notify_error(e.subject, e.text, e.text_params) else: diff --git a/cms/server/contest/handlers/contest.py b/cms/server/contest/handlers/contest.py index 513bf0cc0a..f6deec3508 100644 --- a/cms/server/contest/handlers/contest.py +++ b/cms/server/contest/handlers/contest.py @@ -44,10 +44,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms import config, TOKEN_MODE_MIXED from cms.db import Contest, Submission, Task, UserTest, contest @@ -126,7 +123,7 @@ def choose_contest(self): # the one from the base class is enough to display a 404 page. super().prepare() self.r_params = super().render_params() - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) else: # Select the contest specified on the command line self.contest = Contest.get_from_id( @@ -164,7 +161,7 @@ def get_current_user(self) -> Participation | None: authorization_header = self.request.headers.get( "X-CMS-Authorization", None) if authorization_header is not None: - authorization_header = tornado_web.decode_signed_value(self.application.settings["cookie_secret"], + authorization_header = tornado.web.decode_signed_value(self.application.settings["cookie_secret"], cookie_name, authorization_header) try: diff --git a/cms/server/contest/handlers/main.py b/cms/server/contest/handlers/main.py index 4f34f81c16..4ce2edade7 100644 --- a/cms/server/contest/handlers/main.py +++ b/cms/server/contest/handlers/main.py @@ -44,10 +44,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from sqlalchemy.orm.exc import NoResultFound from cms import config @@ -96,7 +93,7 @@ class RegistrationHandler(ContestHandler): @multi_contest def post(self): if not self.contest.allow_registration: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) create_new_user = self.get_argument("new_user") == "true" @@ -113,7 +110,7 @@ def post(self): .filter(Participation.contest == contest)\ .count() if tot_participants > 0: - raise tornado_web.HTTPError(409) + raise tornado.web.HTTPError(409) # Create participation team = self._get_team() @@ -128,7 +125,7 @@ def post(self): @multi_contest def get(self): if not self.contest.allow_registration: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.r_params["MAX_INPUT_LENGTH"] = self.MAX_INPUT_LENGTH self.r_params["MIN_PASSWORD_LENGTH"] = self.MIN_PASSWORD_LENGTH @@ -158,8 +155,8 @@ def _create_user(self) -> User: if not self.MIN_PASSWORD_LENGTH <= len(password) \ <= self.MAX_INPUT_LENGTH: raise ValueError() - except (tornado_web.MissingArgumentError, ValueError): - raise tornado_web.HTTPError(400) + except (tornado.web.MissingArgumentError, ValueError): + raise tornado.web.HTTPError(400) # Override password with its hash password = hash_password(password) @@ -169,7 +166,7 @@ def _create_user(self) -> User: .filter(User.username == username).count() if tot_users != 0: # HTTP 409: Conflict - raise tornado_web.HTTPError(409) + raise tornado.web.HTTPError(409) # Store new user user = User(first_name, last_name, username, password, email=email) @@ -187,11 +184,11 @@ def _get_user(self) -> User: User.username == username).first() ) if user is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) # Check if password is correct if not validate_password(user.password, password): - raise tornado_web.HTTPError(403) + raise tornado.web.HTTPError(403) return user @@ -204,8 +201,8 @@ def _get_team(self) -> Team | None: self.sql_session.query(Team).filter( Team.code == team_code).one() ) - except (tornado_web.MissingArgumentError, NoResultFound): - raise tornado_web.HTTPError(400) + except (tornado.web.MissingArgumentError, NoResultFound): + raise tornado.web.HTTPError(400) else: team = None @@ -263,7 +260,7 @@ class StartHandler(ContestHandler): Used by a user who wants to start their per_user_time. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(-1) @multi_contest def post(self): @@ -293,7 +290,7 @@ class NotificationsHandler(ContestHandler): refresh_cookie = False - @tornado_web.authenticated + @tornado.web.authenticated @multi_contest def get(self): participation: Participation = self.current_user @@ -325,14 +322,14 @@ class PrintingHandler(ContestHandler): """Serve the interface to print and handle submitted print jobs. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self): participation: Participation = self.current_user if not self.r_params["printing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) printjobs: list[PrintJob] = ( self.sql_session.query(PrintJob) @@ -349,7 +346,7 @@ def get(self): pdf_printing_allowed=config.pdf_printing_allowed, **self.r_params) - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def post(self): @@ -359,7 +356,7 @@ def post(self): self.timestamp, self.request.files) self.sql_session.commit() except PrintingDisabled: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) except UnacceptablePrintJob as e: self.notify_error(e.subject, e.text, e.text_params) else: @@ -375,7 +372,7 @@ class DocumentationHandler(ContestHandler): ...) of the contest. """ - @tornado_web.authenticated + @tornado.web.authenticated @multi_contest def get(self): contest: Contest = self.r_params.get("contest") diff --git a/cms/server/contest/handlers/task.py b/cms/server/contest/handlers/task.py index 182425b7b7..c4cfc416ac 100644 --- a/cms/server/contest/handlers/task.py +++ b/cms/server/contest/handlers/task.py @@ -37,10 +37,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms.server import multi_contest from cmscommon.mimetypes import get_type_for_file_name @@ -55,13 +52,13 @@ class TaskDescriptionHandler(ContestHandler): """Shows the data of a task in the contest. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.render("task_description.html", task=task, **self.r_params) @@ -70,16 +67,16 @@ class TaskStatementViewHandler(FileHandler): """Shows the statement file of a task in the contest. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name: str, lang_code: str): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) if lang_code not in task.statements: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) statement = task.statements[lang_code].digest self.sql_session.close() @@ -96,16 +93,16 @@ class TaskAttachmentViewHandler(FileHandler): """Shows an attachment file of a task in the contest. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name: str, filename: str): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) if filename not in task.attachments: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) attachment = task.attachments[filename].digest self.sql_session.close() diff --git a/cms/server/contest/handlers/tasksubmission.py b/cms/server/contest/handlers/tasksubmission.py index c91e7eb75f..96f5921a35 100644 --- a/cms/server/contest/handlers/tasksubmission.py +++ b/cms/server/contest/handlers/tasksubmission.py @@ -43,10 +43,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from sqlalchemy.orm import joinedload from cms import config, FEEDBACK_LEVEL_FULL @@ -77,7 +74,7 @@ class SubmitHandler(ContestHandler): """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3) @multi_contest def post(self, task_name): @@ -89,7 +86,7 @@ def post(self, task_name): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) # Only set the official bit when the user can compete and we are not in # analysis mode. @@ -126,7 +123,7 @@ class TaskSubmissionsHandler(ContestHandler): """Shows the data of a task in the contest. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name): @@ -134,7 +131,7 @@ def get(self, task_name): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submissions: list[Submission] = ( self.sql_session.query(Submission) @@ -239,17 +236,17 @@ def add_task_score(self, participation: Participation, task: Task, data: dict): data["task_tokened_score"], score_type.max_score, None, task.score_precision, translation=self.translation) - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name, opaque_id): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission = self.get_submission(task, opaque_id) if submission is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) sr = submission.get_result(task.active_dataset) @@ -299,17 +296,17 @@ class SubmissionDetailsHandler(ContestHandler): refresh_cookie = False - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name, opaque_id): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission = self.get_submission(task, opaque_id) if submission is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) sr = submission.get_result(task.active_dataset) score_type = task.active_dataset.score_type_object @@ -340,20 +337,20 @@ class SubmissionFileHandler(FileHandler): """Send back a submission file. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0, 1, 2, 3, 4) @multi_contest def get(self, task_name, opaque_id, filename): if not self.contest.submissions_download_allowed: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission = self.get_submission(task, opaque_id) if submission is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) # The following code assumes that submission.files is a subset # of task.submission_format. CWS will always ensure that for new @@ -370,7 +367,7 @@ def get(self, task_name, opaque_id, filename): stored_filename = re.sub(r'%s$' % extension, '.%l', filename) if stored_filename not in submission.files: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) digest = submission.files[stored_filename].digest self.sql_session.close() @@ -386,17 +383,17 @@ class UseTokenHandler(ContestHandler): """Called when the user try to use a token on a submission. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def post(self, task_name, opaque_id): task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) submission = self.get_submission(task, opaque_id) if submission is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) try: accept_token(self.sql_session, submission, self.timestamp) diff --git a/cms/server/contest/handlers/taskusertest.py b/cms/server/contest/handlers/taskusertest.py index 07da1f9a59..9971967ee8 100644 --- a/cms/server/contest/handlers/taskusertest.py +++ b/cms/server/contest/handlers/taskusertest.py @@ -38,10 +38,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - import tornado4.web as tornado_web -except ImportError: - import tornado.web as tornado_web +import tornado.web from cms import config from cms.db import UserTest, UserTestResult @@ -67,14 +64,14 @@ class UserTestInterfaceHandler(ContestHandler): """Serve the interface to test programs. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self): participation = self.current_user if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) user_tests = dict() user_tests_left = dict() @@ -123,16 +120,16 @@ class UserTestHandler(ContestHandler): refresh_cookie = False - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def post(self, task_name): if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) query_args = dict() @@ -145,7 +142,7 @@ def post(self, task_name): except TestingNotAllowed: logger.warning("User %s tried to make test on task %s.", self.current_user.user.username, task_name) - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) except UnacceptableUserTest as e: logger.info("Sent error: `%s' - `%s'", e.subject, e.formatted_text) self.notify_error(e.subject, e.text, e.text_params) @@ -169,20 +166,20 @@ class UserTestStatusHandler(ContestHandler): refresh_cookie = False - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self, task_name, user_test_num): if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) user_test = self.get_user_test(task, user_test_num) if user_test is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) ur = user_test.get_result(task.active_dataset) data = dict() @@ -224,20 +221,20 @@ class UserTestDetailsHandler(ContestHandler): refresh_cookie = False - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self, task_name, user_test_num): if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) user_test = self.get_user_test(task, user_test_num) if user_test is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) tr = user_test.get_result(task.active_dataset) @@ -249,20 +246,20 @@ class UserTestIOHandler(FileHandler): """Send back a submission file. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self, task_name, user_test_num, io): if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) user_test = self.get_user_test(task, user_test_num) if user_test is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) if io == "input": digest = user_test.input @@ -272,7 +269,7 @@ def get(self, task_name, user_test_num, io): self.sql_session.close() if digest is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) mimetype = 'text/plain' @@ -283,20 +280,20 @@ class UserTestFileHandler(FileHandler): """Send back a submission file. """ - @tornado_web.authenticated + @tornado.web.authenticated @actual_phase_required(0) @multi_contest def get(self, task_name, user_test_num, filename): if not self.r_params["testing_enabled"]: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) task = self.get_task(task_name) if task is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) user_test = self.get_user_test(task, user_test_num) if user_test is None: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) # filename is the name used by the browser, hence is something # like 'foo.c' (and the extension is CMS's preferred extension @@ -314,7 +311,7 @@ def get(self, task_name, user_test_num, filename): # Instead, the original name is used digest = user_test.managers[filename].digest else: - raise tornado_web.HTTPError(404) + raise tornado.web.HTTPError(404) self.sql_session.close() mimetype = get_type_for_file_name(filename) diff --git a/cms/server/util.py b/cms/server/util.py index f1ed3edb4e..3f18da3951 100644 --- a/cms/server/util.py +++ b/cms/server/util.py @@ -39,13 +39,7 @@ import typing -if typing.TYPE_CHECKING: - from tornado.web import RequestHandler -else: - try: - from tornado4.web import RequestHandler - except ImportError: - from tornado.web import RequestHandler +from tornado.web import RequestHandler from cms.db import Session from cms.server.file_middleware import FileServerMiddleware diff --git a/cmstestsuite/unit_tests/cmscontrib/AddAdminTest.py b/cmstestsuite/unit_tests/cmscontrib/AddAdminTest.py index 7aff81f384..2332224922 100755 --- a/cmstestsuite/unit_tests/cmscontrib/AddAdminTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/AddAdminTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Admin diff --git a/cmstestsuite/unit_tests/cmscontrib/AddParticipationTest.py b/cmstestsuite/unit_tests/cmscontrib/AddParticipationTest.py index 9667809827..62131b35c0 100755 --- a/cmstestsuite/unit_tests/cmscontrib/AddParticipationTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/AddParticipationTest.py @@ -21,7 +21,6 @@ import ipaddress import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Participation diff --git a/cmstestsuite/unit_tests/cmscontrib/AddStatementTest.py b/cmstestsuite/unit_tests/cmscontrib/AddStatementTest.py index 1f1370f489..1f8557db33 100755 --- a/cmstestsuite/unit_tests/cmscontrib/AddStatementTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/AddStatementTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Statement diff --git a/cmstestsuite/unit_tests/cmscontrib/AddSubmissionTest.py b/cmstestsuite/unit_tests/cmscontrib/AddSubmissionTest.py index f223cdc360..f17e828c86 100755 --- a/cmstestsuite/unit_tests/cmscontrib/AddSubmissionTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/AddSubmissionTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import File, Submission diff --git a/cmstestsuite/unit_tests/cmscontrib/DumpExporterTest.py b/cmstestsuite/unit_tests/cmscontrib/DumpExporterTest.py index 058e888649..3fb268f75b 100755 --- a/cmstestsuite/unit_tests/cmscontrib/DumpExporterTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/DumpExporterTest.py @@ -22,7 +22,6 @@ import os import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Contest, Executable, Participation, Statement, Submission, \ diff --git a/cmstestsuite/unit_tests/cmscontrib/DumpImporterTest.py b/cmstestsuite/unit_tests/cmscontrib/DumpImporterTest.py index d35a037e0d..1c1c237cf8 100755 --- a/cmstestsuite/unit_tests/cmscontrib/DumpImporterTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/DumpImporterTest.py @@ -22,7 +22,6 @@ import os import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Contest, User, FSObject, Session, version diff --git a/cmstestsuite/unit_tests/cmscontrib/ImportContestTest.py b/cmstestsuite/unit_tests/cmscontrib/ImportContestTest.py index 0745d277fc..045f745f01 100755 --- a/cmstestsuite/unit_tests/cmscontrib/ImportContestTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/ImportContestTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Contest, SessionGen, Submission, User diff --git a/cmstestsuite/unit_tests/cmscontrib/ImportDatasetTest.py b/cmstestsuite/unit_tests/cmscontrib/ImportDatasetTest.py index 9a8e43425f..59fd6eba00 100755 --- a/cmstestsuite/unit_tests/cmscontrib/ImportDatasetTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/ImportDatasetTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Dataset, SessionGen diff --git a/cmstestsuite/unit_tests/cmscontrib/ImportTaskTest.py b/cmstestsuite/unit_tests/cmscontrib/ImportTaskTest.py index 867666fedf..3b568c7310 100755 --- a/cmstestsuite/unit_tests/cmscontrib/ImportTaskTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/ImportTaskTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import SessionGen, Submission, Task diff --git a/cmstestsuite/unit_tests/cmscontrib/ImportTeamTest.py b/cmstestsuite/unit_tests/cmscontrib/ImportTeamTest.py index 88c516d2e1..391ce45204 100755 --- a/cmstestsuite/unit_tests/cmscontrib/ImportTeamTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/ImportTeamTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import SessionGen, Team diff --git a/cmstestsuite/unit_tests/cmscontrib/ImportUserTest.py b/cmstestsuite/unit_tests/cmscontrib/ImportUserTest.py index e96c351fb9..f87cef2e67 100755 --- a/cmstestsuite/unit_tests/cmscontrib/ImportUserTest.py +++ b/cmstestsuite/unit_tests/cmscontrib/ImportUserTest.py @@ -20,7 +20,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Participation, SessionGen, User diff --git a/cmstestsuite/unit_tests/db/filecacher_test.py b/cmstestsuite/unit_tests/db/filecacher_test.py index 44177f6ce4..d558088f9a 100755 --- a/cmstestsuite/unit_tests/db/filecacher_test.py +++ b/cmstestsuite/unit_tests/db/filecacher_test.py @@ -29,7 +29,6 @@ import unittest from io import BytesIO -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db.filecacher import FileCacher diff --git a/cmstestsuite/unit_tests/grading/ParameterTypesTest.py b/cmstestsuite/unit_tests/grading/ParameterTypesTest.py index c7c56af41b..3f87f1cfbc 100755 --- a/cmstestsuite/unit_tests/grading/ParameterTypesTest.py +++ b/cmstestsuite/unit_tests/grading/ParameterTypesTest.py @@ -27,10 +27,7 @@ # Monkey-patch: Tornado 4.5.3 does not work on Python 3.11 by default collections.MutableMapping = collections.abc.MutableMapping -try: - from tornado4.web import MissingArgumentError -except ImportError: - from tornado.web import MissingArgumentError +from tornado.web import MissingArgumentError from cms.grading.ParameterTypes import ParameterTypeString, \ ParameterTypeInt, ParameterTypeChoice, ParameterTypeCollection diff --git a/cmstestsuite/unit_tests/grading/scoring_test.py b/cmstestsuite/unit_tests/grading/scoring_test.py index e1008ddc1a..c7b95969f3 100755 --- a/cmstestsuite/unit_tests/grading/scoring_test.py +++ b/cmstestsuite/unit_tests/grading/scoring_test.py @@ -23,7 +23,6 @@ import unittest from datetime import timedelta -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.grading.scoring import task_score diff --git a/cmstestsuite/unit_tests/server/contest/authentication_test.py b/cmstestsuite/unit_tests/server/contest/authentication_test.py index e075ff7ea5..d98eee6c50 100755 --- a/cmstestsuite/unit_tests/server/contest/authentication_test.py +++ b/cmstestsuite/unit_tests/server/contest/authentication_test.py @@ -25,7 +25,6 @@ from datetime import timedelta from unittest.mock import patch -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms import config diff --git a/cmstestsuite/unit_tests/server/contest/communication_test.py b/cmstestsuite/unit_tests/server/contest/communication_test.py index cda319f5ba..2f4e4f990c 100755 --- a/cmstestsuite/unit_tests/server/contest/communication_test.py +++ b/cmstestsuite/unit_tests/server/contest/communication_test.py @@ -23,7 +23,6 @@ import unittest from datetime import timedelta -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import Question diff --git a/cmstestsuite/unit_tests/server/contest/printing_test.py b/cmstestsuite/unit_tests/server/contest/printing_test.py index af213e76b0..ffe8a85ae6 100755 --- a/cmstestsuite/unit_tests/server/contest/printing_test.py +++ b/cmstestsuite/unit_tests/server/contest/printing_test.py @@ -24,7 +24,6 @@ from collections import namedtuple from unittest.mock import Mock, patch -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms import config diff --git a/cmstestsuite/unit_tests/server/contest/submission/check_test.py b/cmstestsuite/unit_tests/server/contest/submission/check_test.py index 54cc6c5f4b..18737a5ff2 100755 --- a/cmstestsuite/unit_tests/server/contest/submission/check_test.py +++ b/cmstestsuite/unit_tests/server/contest/submission/check_test.py @@ -20,7 +20,6 @@ from datetime import timedelta from unittest.mock import call, patch -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.db import UserTest, Submission diff --git a/cmstestsuite/unit_tests/server/contest/submission/utils_test.py b/cmstestsuite/unit_tests/server/contest/submission/utils_test.py index eaa558843c..a5e6fc3571 100755 --- a/cmstestsuite/unit_tests/server/contest/submission/utils_test.py +++ b/cmstestsuite/unit_tests/server/contest/submission/utils_test.py @@ -22,7 +22,6 @@ from datetime import timedelta from unittest.mock import MagicMock, patch -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms import config diff --git a/cmstestsuite/unit_tests/server/contest/submission/workflow_test.py b/cmstestsuite/unit_tests/server/contest/submission/workflow_test.py index c0e672b9ff..752025e22b 100755 --- a/cmstestsuite/unit_tests/server/contest/submission/workflow_test.py +++ b/cmstestsuite/unit_tests/server/contest/submission/workflow_test.py @@ -21,7 +21,6 @@ from datetime import timedelta from unittest.mock import MagicMock, PropertyMock, patch, sentinel, ANY -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms import config diff --git a/cmstestsuite/unit_tests/server/contest/tokening_test.py b/cmstestsuite/unit_tests/server/contest/tokening_test.py index da83212936..13a13bb2f1 100755 --- a/cmstestsuite/unit_tests/server/contest/tokening_test.py +++ b/cmstestsuite/unit_tests/server/contest/tokening_test.py @@ -24,7 +24,6 @@ from datetime import timedelta from unittest.mock import patch -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms import TOKEN_MODE_INFINITE, TOKEN_MODE_DISABLED, TOKEN_MODE_FINITE diff --git a/cmstestsuite/unit_tests/service/ProxyServiceTest.py b/cmstestsuite/unit_tests/service/ProxyServiceTest.py index 246732e9ed..88dbf155ac 100755 --- a/cmstestsuite/unit_tests/service/ProxyServiceTest.py +++ b/cmstestsuite/unit_tests/service/ProxyServiceTest.py @@ -30,7 +30,6 @@ import gevent -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.service.ProxyService import ProxyService diff --git a/cmstestsuite/unit_tests/service/ScoringServiceTest.py b/cmstestsuite/unit_tests/service/ScoringServiceTest.py index dbc62658a3..c5bff33b10 100755 --- a/cmstestsuite/unit_tests/service/ScoringServiceTest.py +++ b/cmstestsuite/unit_tests/service/ScoringServiceTest.py @@ -32,7 +32,6 @@ import gevent -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.service.ScoringService import ScoringService diff --git a/cmstestsuite/unit_tests/service/esoperations_test.py b/cmstestsuite/unit_tests/service/esoperations_test.py index 5702c8df91..a977fcec97 100755 --- a/cmstestsuite/unit_tests/service/esoperations_test.py +++ b/cmstestsuite/unit_tests/service/esoperations_test.py @@ -23,7 +23,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.io.priorityqueue import PriorityQueue diff --git a/cmstestsuite/unit_tests/service/scoringoperations_test.py b/cmstestsuite/unit_tests/service/scoringoperations_test.py index d1430745d7..8fc2b4815d 100755 --- a/cmstestsuite/unit_tests/service/scoringoperations_test.py +++ b/cmstestsuite/unit_tests/service/scoringoperations_test.py @@ -23,7 +23,6 @@ import unittest -# Needs to be first to allow for monkey patching the DB connection string. from cmstestsuite.unit_tests.databasemixin import DatabaseMixin from cms.service.scoringoperations import ScoringOperation, get_operations