Skip to content

Commit

Permalink
Compatibility with Python 3.12.
Browse files Browse the repository at this point in the history
Inspired by ioi-2024@0f044fd
  • Loading branch information
veluca93 committed Nov 16, 2024
1 parent 98ad9a2 commit 1a7c1ef
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 45 deletions.
7 changes: 7 additions & 0 deletions cms/io/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
from datetime import datetime, timedelta
from functools import wraps

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/contestannouncement.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"""

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/contestquestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/contestuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
import re
import zipfile

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/handlers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
import logging
import traceback

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
import logging
import traceback

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
import ipaddress
import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
import logging
import re

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@

import logging

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/tasksubmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
import logging
import re

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/contest/handlers/taskusertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
import logging
import re

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
7 changes: 7 additions & 0 deletions cms/server/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
from functools import wraps
from urllib.parse import quote, urlencode

import collections
try:
collections.MutableMapping
except:
# 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 RequestHandler
except ImportError:
Expand Down
10 changes: 5 additions & 5 deletions cmscontrib/loaders/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import imp
import logging
import os
import subprocess
Expand Down Expand Up @@ -145,10 +144,11 @@ def get_task(self, get_statement=True):
task_cms_conf = None
if os.path.exists(task_cms_conf_path):
logger.info("Found additional CMS options for task %s.", name)
with open(task_cms_conf_path, 'rb') as f:
task_cms_conf = imp.load_module('cms_conf', f,
task_cms_conf_path,
('.py', 'r', imp.PY_SOURCE))
import importlib.util
spec = importlib.util.spec_from_file_location(
'cms_conf', task_cms_conf_path)
task_cms_conf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(task_cms_conf)
if task_cms_conf is not None and hasattr(task_cms_conf, "general"):
args.update(task_cms_conf.general)

Expand Down
7 changes: 7 additions & 0 deletions cmstestsuite/unit_tests/grading/ParameterTypesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

import unittest

import collections
try:
collections.MutableMapping
except:
# 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:
Expand Down
Loading

0 comments on commit 1a7c1ef

Please sign in to comment.