Remove dependency on django.utils.six

This is done to prepare for upgrade to Django 3.x, which drops six.

Refs #1649
This commit is contained in:
Quantum 2021-10-02 00:03:36 -04:00 committed by Guanzhong Chen
parent 99010eb00c
commit b785d890e1
7 changed files with 13 additions and 23 deletions

View File

@ -1,7 +1,5 @@
from abc import ABCMeta, abstractmethod, abstractproperty
from django.utils import six
class abstractclassmethod(classmethod):
__isabstractmethod__ = True
@ -11,7 +9,7 @@ class abstractclassmethod(classmethod):
super(abstractclassmethod, self).__init__(callable)
class BaseContestFormat(six.with_metaclass(ABCMeta)):
class BaseContestFormat(metaclass=ABCMeta):
@abstractmethod
def __init__(self, contest, config):
self.config = config

View File

@ -1,5 +1,3 @@
from django.utils import six
formats = {}
@ -13,4 +11,4 @@ def register_contest_format(name):
def choices():
return [(key, value.name) for key, value in sorted(six.iteritems(formats))]
return [(key, value.name) for key, value in sorted(formats.items())]

View File

@ -1,5 +1,3 @@
from django.utils import six
from judge.ratings import rating_class, rating_name, rating_progress
from . import registry
@ -8,7 +6,7 @@ def _get_rating_value(func, obj):
if obj is None:
return None
if isinstance(obj, six.integer_types):
if isinstance(obj, int):
return func(obj)
else:
return func(obj.rating)

View File

@ -1,5 +1,4 @@
from django.conf import settings
from django.utils import six
from django.utils.safestring import SafeData, mark_safe
if settings.USE_I18N:
@ -25,7 +24,7 @@ if settings.USE_I18N:
else:
translation_object = translation(get_language())
result = getattr(translation_object, translation_function)(eol_message)
if not isinstance(result, six.text_type):
if not isinstance(result, str):
result = result.decode('utf-8')
if isinstance(message, SafeData):

View File

@ -40,7 +40,6 @@ import requests
from django.conf import settings
from django.contrib.auth.password_validation import CommonPasswordValidator
from django.core.exceptions import ValidationError
from django.utils.six import string_types
from django.utils.translation import gettext as _, ungettext
from judge.utils.unicode import utf8bytes
@ -83,7 +82,7 @@ def pwned_password(password):
"""
Checks a password against the Pwned Passwords database.
"""
if not isinstance(password, string_types):
if not isinstance(password, str):
raise TypeError('Password values to check must be strings.')
password_hash = hashlib.sha1(utf8bytes(password)).hexdigest().upper()
prefix, suffix = password_hash[:5], password_hash[5:]
@ -106,7 +105,7 @@ class PwnedPasswordsValidator(object):
error_message = error_message or self.DEFAULT_PWNED_MESSAGE
# If there is no plural, use the same message for both forms.
if isinstance(error_message, string_types):
if isinstance(error_message, str):
singular, plural = error_message, error_message
else:
singular, plural = error_message

View File

@ -5,7 +5,6 @@ from django.db.models import Field
from django.db.models.expressions import RawSQL
from django.db.models.sql.constants import INNER, LOUTER
from django.db.models.sql.datastructures import Join
from django.utils import six
from judge.utils.cachedict import CacheDict
@ -66,7 +65,7 @@ def RawSQLColumn(model, field=None):
if isinstance(model, Field):
field = model
model = field.model
if isinstance(field, six.string_types):
if isinstance(field, str):
field = model._meta.get_field(field)
return RawSQL('%s.%s' % (model._meta.db_table, field.get_attname_column()[1]), ())

View File

@ -2,7 +2,6 @@ from collections import defaultdict
from functools import partial
from django.shortcuts import render
from django.utils import six
from django.utils.translation import gettext as _
from packaging import version
@ -66,12 +65,12 @@ def version_matrix(request):
for runtime in RuntimeVersion.objects.filter(judge__online=True).order_by('priority'):
matrix[runtime.judge_id][runtime.language_id].append(runtime)
for judge, data in six.iteritems(matrix):
for judge, data in matrix.items():
name_tuple = judges[judge].rpartition('.')
groups[name_tuple[0] or name_tuple[-1]].append((judges[judge], data))
matrix = {}
for group, data in six.iteritems(groups):
for group, data in groups.items():
if len(data) == 1:
judge, data = data[0]
matrix[judge] = data
@ -94,14 +93,14 @@ def version_matrix(request):
if ds[i] != rep:
matrix[j] = x
for data in six.itervalues(matrix):
for language, versions in six.iteritems(data):
for data in matrix.values():
for language, versions in data.items():
versions.versions = [version.parse(runtime.version) for runtime in versions]
if versions.versions > latest[language]:
latest[language] = versions.versions
for data in six.itervalues(matrix):
for language, versions in six.iteritems(data):
for data in matrix.values():
for language, versions in data.items():
versions.is_latest = versions.versions == latest[language]
languages = sorted(languages, key=lambda lang: version.parse(lang.name))