Skip to content
Merged
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
7 changes: 2 additions & 5 deletions cms/io/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 6 additions & 9 deletions cms/server/admin/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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".

Expand Down Expand Up @@ -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.

Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions cms/server/admin/handlers/contestannouncement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 3 additions & 6 deletions cms/server/admin/handlers/contestquestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"

Expand Down
13 changes: 5 additions & 8 deletions cms/server/admin/handlers/contestuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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", ""),
Expand Down
13 changes: 5 additions & 8 deletions cms/server/admin/handlers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions cms/server/admin/handlers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions cms/server/contest/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
11 changes: 4 additions & 7 deletions cms/server/contest/handlers/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions cms/server/contest/handlers/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
Loading