Skip to content

Commit

Permalink
Remove dependency on django.utils.six
Browse files Browse the repository at this point in the history
This is done to prepare for upgrade to Django 3.x, which drops six.

Refs #1649
  • Loading branch information
quantum5 committed Oct 2, 2021
1 parent 99010eb commit b785d89
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
4 changes: 1 addition & 3 deletions judge/contest_format/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABCMeta, abstractmethod, abstractproperty

from django.utils import six


class abstractclassmethod(classmethod):
__isabstractmethod__ = True
Expand All @@ -11,7 +9,7 @@ def __init__(self, callable):
super(abstractclassmethod, self).__init__(callable)


class BaseContestFormat(six.with_metaclass(ABCMeta)):
class BaseContestFormat(metaclass=ABCMeta):
@abstractmethod
def __init__(self, contest, config):
self.config = config
Expand Down
4 changes: 1 addition & 3 deletions judge/contest_format/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.utils import six

formats = {}


Expand All @@ -13,4 +11,4 @@ def register_class(contest_format_class):


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())]
4 changes: 1 addition & 3 deletions judge/jinja2/rating.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.utils import six

from judge.ratings import rating_class, rating_name, rating_progress
from . import registry

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions judge/user_translations.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -25,7 +24,7 @@ def do_translate(message, translation_function):
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):
Expand Down
5 changes: 2 additions & 3 deletions judge/utils/pwned.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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
Expand Down Expand Up @@ -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:]
Expand All @@ -106,7 +105,7 @@ def __init__(self, error_message=None, help_message=None):
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
Expand Down
3 changes: 1 addition & 2 deletions judge/utils/raw_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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

Expand Down Expand Up @@ -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]), ())

Expand Down
13 changes: 6 additions & 7 deletions judge/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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

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

0 comments on commit b785d89

Please sign in to comment.