Skip to content

Commit

Permalink
pyupgrade: automatic removal of Python2 code
Browse files Browse the repository at this point in the history
pyupgrade --py3-plus --keep-percent-format
I excluded tagrecommendation, similarity and clustering
(For the latter I didn't know if Py2 should still be supported)
I tweaked some small changes by hand
  • Loading branch information
Bomme committed Feb 2, 2023
1 parent 1be11d3 commit c18b3b7
Show file tree
Hide file tree
Showing 323 changed files with 593 additions and 1,211 deletions.
3 changes: 1 addition & 2 deletions _docs/api/add_examples_to_api_docs_source_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
import sys
Expand Down Expand Up @@ -28,7 +27,7 @@ def get_formatted_examples_for_view(view_name):
return output


with open('source/resources.rst', 'r') as f:
with open('source/resources.rst') as f:
newlines = []
for line in f.readlines():
if '{{examples_' in line:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Generate skeleton for documentation,
# add essentia documentation links by hand

from __future__ import print_function

from future import standard_library
standard_library.install_aliases()
from builtins import range
import urllib.request, urllib.error, urllib.parse,json


Expand Down
9 changes: 4 additions & 5 deletions _docs/api/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Freesound API documentation build configuration file, created by
# sphinx-quickstart on Mon Sep 6 11:41:46 2010.
Expand Down Expand Up @@ -37,8 +36,8 @@
master_doc = 'index'

# General information about the project.
project = u'Freesound API'
copyright = u'2014, Universitat Pompeu Fabra'
project = 'Freesound API'
copyright = '2014, Universitat Pompeu Fabra'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -172,8 +171,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'FreesoundAPI.tex', u'Freesound API Documentation',
u'Vincent Akkermans, Bram de Jong', 'manual'),
('index', 'FreesoundAPI.tex', 'Freesound API Documentation',
'Vincent Akkermans, Bram de Jong', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
36 changes: 17 additions & 19 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

#
# Freesound is (c) MUSIC TECHNOLOGY GROUP, UNIVERSITAT POMPEU FABRA
#
Expand Down Expand Up @@ -64,9 +62,9 @@ class DeletedUserAdmin(admin.ModelAdmin):
search_fields = ('=username',)

def get_object_link(self, obj):
return '<a href="{0}" target="_blank">{1}</a>'.format(
return '<a href="{}" target="_blank">{}</a>'.format(
reverse('admin:accounts_deleteduser_change', args=[obj.id]),
'DeletedUser: {0}'.format(obj.username))
'DeletedUser: {}'.format(obj.username))
get_object_link.short_description = 'DeletedUser'
get_object_link.allow_tags = True
get_object_link.admin_order_field = 'username'
Expand All @@ -75,13 +73,13 @@ def get_view_link(self, obj):
if obj.user is None:
return '-'
else:
return '<a href="{0}" target="_blank">{1}</a>'.format(
return '<a href="{}" target="_blank">{}</a>'.format(
reverse('account', args=[obj.user.username]), obj.user.username)
get_view_link.short_description = 'View on site'
get_view_link.allow_tags = True

def get_num_sounds(self, obj):
return '{0}'.format(obj.profile.num_sounds)
return '{}'.format(obj.profile.num_sounds)
get_num_sounds.short_description = '# sounds'


Expand Down Expand Up @@ -148,7 +146,7 @@ class FreesoundUserAdmin(DjangoObjectActions, UserAdmin):

def get_queryset(self, request):
# Override 'get_queryset' to optimize query by using select_related on appropriate fields
qs = super(FreesoundUserAdmin, self).get_queryset(request)
qs = super().get_queryset(request)
qs = qs.select_related('profile')
return qs

Expand All @@ -158,22 +156,22 @@ def has_delete_permission(self, request, obj=None):
return False

def get_view_link(self, obj):
return '<a href="{0}" target="_blank">{1}</a>'.format(
return '<a href="{}" target="_blank">{}</a>'.format(
reverse('account', args=[obj.username]), obj.username)
get_view_link.short_description = 'View on site'
get_view_link.allow_tags = True

def get_num_sounds(self, obj):
return '{0}'.format(obj.profile.num_sounds)
return '{}'.format(obj.profile.num_sounds)
get_num_sounds.short_description = '# sounds'

def get_num_posts(self, obj):
return '{0}'.format(obj.profile.num_posts)
return '{}'.format(obj.profile.num_posts)
get_num_posts.short_description = '# posts'

def get_actions(self, request):
# Disable the "delete" action in the list
actions = super(FreesoundUserAdmin, self).get_actions(request)
actions = super().get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
Expand All @@ -183,7 +181,7 @@ def delete_preserve_sounds(self, request, obj):
if request.method == "POST":
delete_action = tasks.DELETE_USER_KEEP_SOUNDS_ACTION_NAME
delete_reason = DeletedUser.DELETION_REASON_DELETED_BY_ADMIN
web_logger.info('Requested async deletion of user {0} - {1}'.format(obj.id, delete_action))
web_logger.info('Requested async deletion of user {} - {}'.format(obj.id, delete_action))

# Create a UserDeletionRequest with a status of 'Deletion action was triggered'
UserDeletionRequest.objects.create(user_from=request.user,
Expand Down Expand Up @@ -215,7 +213,7 @@ def delete_include_sounds(self, request, obj):
if request.method == "POST":
delete_action = tasks.DELETE_USER_DELETE_SOUNDS_ACTION_NAME
delete_reason = DeletedUser.DELETION_REASON_DELETED_BY_ADMIN
web_logger.info('Requested async deletion of user {0} - {1}'.format(obj.id, delete_action))
web_logger.info('Requested async deletion of user {} - {}'.format(obj.id, delete_action))

# Create a UserDeletionRequest with a status of 'Deletion action was triggered'
UserDeletionRequest.objects.create(user_from=request.user,
Expand Down Expand Up @@ -253,7 +251,7 @@ def delete_spammer(self, request, obj):
if request.method == "POST":
delete_action = tasks.DELETE_SPAMMER_USER_ACTION_NAME
delete_reason = DeletedUser.DELETION_REASON_SPAMMER
web_logger.info('Requested async deletion of user {0} - {1}'.format(obj.id, delete_action))
web_logger.info('Requested async deletion of user {} - {}'.format(obj.id, delete_action))

# Create a UserDeletionRequest with a status of 'Deletion action was triggered'
UserDeletionRequest.objects.create(user_from=request.user,
Expand Down Expand Up @@ -290,7 +288,7 @@ def full_delete(self, request, obj):
if request.method == "POST":
delete_action = tasks.FULL_DELETE_USER_ACTION_NAME
delete_reason = DeletedUser.DELETION_REASON_DELETED_BY_ADMIN
web_logger.info('Requested async deletion of user {0} - {1}'.format(obj.id, delete_action))
web_logger.info('Requested async deletion of user {} - {}'.format(obj.id, delete_action))

# Create a UserDeletionRequest with a status of 'Deletion action was triggered'
UserDeletionRequest.objects.create(user_from=request.user,
Expand Down Expand Up @@ -373,16 +371,16 @@ class UserDeletionRequestAdmin(admin.ModelAdmin):

def get_queryset(self, request):
# Override 'get_queryset' to optimize query by using select_related on appropriate fields
qs = super(UserDeletionRequestAdmin, self).get_queryset(request)
qs = super().get_queryset(request)
qs = qs.select_related('user_from', 'deleted_user', 'user_to')
return qs

def deleted_user_link(self, obj):
if obj.deleted_user is None:
return '-'
return '<a href="{0}" target="_blank">{1}</a>'.format(
return '<a href="{}" target="_blank">{}</a>'.format(
reverse('admin:accounts_deleteduser_change', args=[obj.deleted_user_id]),
'DeletedUser: {0}'.format(obj.deleted_user.username))
'DeletedUser: {}'.format(obj.deleted_user.username))

deleted_user_link.allow_tags = True
deleted_user_link.admin_order_field = 'deleted_user'
Expand All @@ -391,7 +389,7 @@ def deleted_user_link(self, obj):
def user_to_link(self, obj):
if obj.user_to is None:
return '-'
return '<a href="{0}" target="_blank">{1}</a>'.format(
return '<a href="{}" target="_blank">{}</a>'.format(
reverse('admin:auth_user_change', args=[obj.user_to_id]), obj.user_to.username)

user_to_link.allow_tags = True
Expand Down
41 changes: 19 additions & 22 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Freesound is (c) MUSIC TECHNOLOGY GROUP, UNIVERSITAT POMPEU FABRA
#
Expand All @@ -21,8 +20,6 @@

import logging

from builtins import object
from builtins import str
from captcha.fields import ReCaptchaField
from django import forms
from django.conf import settings
Expand Down Expand Up @@ -122,7 +119,7 @@ class TermsOfServiceForm(forms.Form):
class TermsOfServiceFormBW(TermsOfServiceForm):

def __init__(self, *args, **kwargs):
super(TermsOfServiceFormBW, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['accepted_tos'].widget.attrs['class'] = 'bw-checkbox'
self.fields['accepted_license_change'].widget.attrs['class'] = 'bw-checkbox'

Expand All @@ -148,7 +145,7 @@ class FileChoiceForm(forms.Form):
files = forms.MultipleChoiceField()

def __init__(self, files, *args, **kwargs):
super(FileChoiceForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
choices = list(files.items())
self.fields['files'].choices = choices

Expand All @@ -160,7 +157,7 @@ def get_user_by_email(email):
class UsernameField(forms.CharField):
""" Username field, 3~30 characters, allows only alphanumeric chars, required by default """
def __init__(self, required=True):
super(UsernameField, self).__init__(
super().__init__(
label="Username",
min_length=3,
max_length=30,
Expand Down Expand Up @@ -236,7 +233,7 @@ def clean_email1(self):
return email1

def clean(self):
cleaned_data = super(RegistrationForm, self).clean()
cleaned_data = super().clean()
return cleaned_data

def save(self):
Expand All @@ -261,7 +258,7 @@ class BwRegistrationForm(RegistrationForm):
def __init__(self, *args, **kwargs):
kwargs.update(dict(auto_id='id_%s_registration'))
kwargs.update(dict(label_suffix=''))
super(BwRegistrationForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# Customize some placeholders and classes, remove labels and help texts
self.fields['username'].label = False
Expand Down Expand Up @@ -289,14 +286,14 @@ class BwProblemsLoggingInForm(forms.Form):
username_or_email = forms.CharField(label="", help_text="", max_length=254)

def __init__(self, *args, **kwargs):
super(BwProblemsLoggingInForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['username_or_email'].widget.attrs['placeholder'] = 'Your email or username'


class FsAuthenticationForm(AuthenticationForm):

def __init__(self, *args, **kwargs):
super(FsAuthenticationForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.error_messages.update({
'inactive': mark_safe("You are trying to log in with an inactive account, please <a href=\"%s\">activate "
"your account</a> first." % reverse("accounts-resend-activation")),
Expand All @@ -309,7 +306,7 @@ def __init__(self, *args, **kwargs):
class BwFsAuthenticationForm(FsAuthenticationForm):

def __init__(self, *args, **kwargs):
super(BwFsAuthenticationForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# Customize form placeholders and remove labels
self.fields['username'].label = False
Expand Down Expand Up @@ -356,7 +353,7 @@ def __init__(self, request, *args, **kwargs):
kwargs.update(initial={
'username': request.user.username
})
super(ProfileForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self.n_times_changed_username = OldUsername.objects.filter(user_id=self.request.user.id).count()
if self.n_times_changed_username < 1:
Expand Down Expand Up @@ -422,7 +419,7 @@ def clean_sound_signature(self):

return sound_signature

class Meta(object):
class Meta:
model = Profile
fields = ('home_page', 'about', 'signature', 'sound_signature', 'is_adult', 'not_shown_in_online_users_list', )

Expand All @@ -437,7 +434,7 @@ class BwProfileForm(ProfileForm):

def __init__(self, *args, **kwargs):
kwargs.update(dict(label_suffix=''))
super(BwProfileForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# Customize some placeholders and classes, remove labels and help texts
self.fields['username'].widget.attrs['placeholder'] = 'Write your name here (30 characters maximum)'
Expand Down Expand Up @@ -465,7 +462,7 @@ def __init__(self, *args, **kwargs):
self.fields['is_adult'].help_text = False
self.fields['not_shown_in_online_users_list'].widget = forms.HiddenInput()

class Meta(object):
class Meta:
model = Profile
fields = ('username', 'home_page', 'about', 'signature', 'sound_signature', 'is_adult', )

Expand All @@ -477,16 +474,16 @@ class EmailResetForm(forms.Form):
def __init__(self, *args, **kwargs):
# Using init function to pass user variable so later we can perform check_password in clean_password function
self.user = kwargs.pop('user', None)
super(EmailResetForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def clean_password(self):
if not self.user.check_password(self.cleaned_data["password"]):
raise forms.ValidationError("Incorrect password.")
return self.cleaned_data['password']


DELETE_CHOICES = [('only_user', mark_safe(u'<span>Delete only my user account information</span>')),
('delete_sounds', mark_safe(u'<span>Delete my user account information, my sounds and packs</span>'))]
DELETE_CHOICES = [('only_user', mark_safe('<span>Delete only my user account information</span>')),
('delete_sounds', mark_safe('<span>Delete my user account information, my sounds and packs</span>'))]


class DeleteUserForm(forms.Form):
Expand Down Expand Up @@ -525,13 +522,13 @@ def __init__(self, *args, **kwargs):
'delete_sounds': 'only_user',
'encrypted_link': encrypted_link
}
super(DeleteUserForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class BwDeleteUserForm(DeleteUserForm):

def __init__(self, *args, **kwargs):
super(BwDeleteUserForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['delete_sounds'].label = False
# NOTE: the line below will add 'bw-radio' to all individual radio elements of
# forms.RadioSelect but also to the main ul element that wraps them all. This is not
Expand All @@ -551,7 +548,7 @@ class EmailSettingsForm(forms.Form):
class BwEmailSettingsForm(EmailSettingsForm):

def __init__(self, *args, **kwargs):
super(BwEmailSettingsForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['email_types'].label = False
# NOTE: the line below will add 'bw-checkbox' to all individual checkbox elements of
# forms.CheckboxSelectMultiple but also to the main ul element that wraps them all. This is not
Expand Down Expand Up @@ -629,7 +626,7 @@ def save(self, domain_override=None,
class BwSetPasswordForm(SetPasswordForm):

def __init__(self, *args, **kwargs):
super(BwSetPasswordForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# Customize some placeholders and classes, remove labels and help texts
self.fields['new_password1'].label = False
Expand Down
1 change: 0 additions & 1 deletion accounts/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion accounts/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion accounts/management/commands/clean_old_tmp_upload_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# See AUTHORS file.
#

from __future__ import print_function

from django.core.management.base import BaseCommand
from django.conf import settings
Expand Down
2 changes: 0 additions & 2 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-15 11:33
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions accounts/migrations/0002_profile_is_deleted_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-07-28 15:13
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions accounts/migrations/0003_auto_20160914_1100.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-09-14 11:00
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
Loading

0 comments on commit c18b3b7

Please sign in to comment.