Skip to content

Commit f8875e9

Browse files
authored
Merge pull request #421 from claudep/remove_python2_leftovers
Removed old syntax used to ensure Python 2 compatibility
2 parents db343bb + 592ca75 commit f8875e9

30 files changed

+96
-171
lines changed

docs/conf.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Django FileBrowser documentation build configuration file, created by
42
# sphinx-quickstart on Sun Dec 5 19:11:46 2010.
53
#
@@ -43,8 +41,8 @@
4341
master_doc = 'index'
4442

4543
# General information about the project.
46-
project = u'Django FileBrowser'
47-
copyright = u'2022, Patrick Kranzlmueller'
44+
project = 'Django FileBrowser'
45+
copyright = '2022, Patrick Kranzlmueller'
4846

4947
# The version info for the project you're documenting, acts as replacement for
5048
# |version| and |release|, also used in various other places throughout the
@@ -182,8 +180,8 @@
182180
# Grouping the document tree into LaTeX files. List of tuples
183181
# (source start file, target name, title, author, documentclass [howto/manual]).
184182
latex_documents = [
185-
('index', 'DjangoFileBrowser.tex', u'Django FileBrowser Documentation',
186-
u'Patrick Kranzlmueller', 'manual'),
183+
('index', 'DjangoFileBrowser.tex', 'Django FileBrowser Documentation',
184+
'Patrick Kranzlmueller', 'manual'),
187185
]
188186

189187
# The name of an image file (relative to this directory) to place at the top of
@@ -215,8 +213,8 @@
215213
# One entry per manual page. List of tuples
216214
# (source start file, name, description, authors, manual section).
217215
man_pages = [
218-
('index', 'djangofilebrowser', u'Django FileBrowser Documentation',
219-
[u'Patrick Kranzlmueller'], 1)
216+
('index', 'djangofilebrowser', 'Django FileBrowser Documentation',
217+
['Patrick Kranzlmueller'], 1)
220218
]
221219

222220
if not on_rtd: # only import and set the theme if we're building docs locally

docs/fieldswidgets.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Return a :ref:`fileobject` from a `FileField <https://docs.djangoproject.com/en/
9090
9191
from filebrowser.base import FileObject
9292
93-
image_upload = models.ImageField(u"Image (Upload)", max_length=250, upload_to=image_upload_path, blank=True)
93+
image_upload = models.ImageField("Image (Upload)", max_length=250, upload_to=image_upload_path, blank=True)
9494
9595
def image(self):
9696
if self.image_upload:

filebrowser/actions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# coding: utf-8
2-
31
import os
42
import tempfile
53

@@ -52,33 +50,33 @@ def transpose_image(request, fileobjects, operation):
5250
def flip_horizontal(request, fileobjects):
5351
"Flip image horizontally"
5452
transpose_image(request, fileobjects, 0)
55-
flip_horizontal.short_description = _(u'Flip horizontal')
53+
flip_horizontal.short_description = _('Flip horizontal')
5654
flip_horizontal.applies_to = applies_to_all_images
5755

5856

5957
def flip_vertical(request, fileobjects):
6058
"Flip image vertically"
6159
transpose_image(request, fileobjects, 1)
62-
flip_vertical.short_description = _(u'Flip vertical')
60+
flip_vertical.short_description = _('Flip vertical')
6361
flip_vertical.applies_to = applies_to_all_images
6462

6563

6664
def rotate_90_clockwise(request, fileobjects):
6765
"Rotate image 90 degrees clockwise"
6866
transpose_image(request, fileobjects, 4)
69-
rotate_90_clockwise.short_description = _(u'Rotate 90° CW')
67+
rotate_90_clockwise.short_description = _('Rotate 90° CW')
7068
rotate_90_clockwise.applies_to = applies_to_all_images
7169

7270

7371
def rotate_90_counterclockwise(request, fileobjects):
7472
"Rotate image 90 degrees counterclockwise"
7573
transpose_image(request, fileobjects, 2)
76-
rotate_90_counterclockwise.short_description = _(u'Rotate 90° CCW')
74+
rotate_90_counterclockwise.short_description = _('Rotate 90° CCW')
7775
rotate_90_counterclockwise.applies_to = applies_to_all_images
7876

7977

8078
def rotate_180(request, fileobjects):
8179
"Rotate image 180 degrees"
8280
transpose_image(request, fileobjects, 3)
83-
rotate_180.short_description = _(u'Rotate 180°')
81+
rotate_180.short_description = _('Rotate 180°')
8482
rotate_180.applies_to = applies_to_all_images

filebrowser/base.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
# coding: utf-8
2-
31
import datetime
42
import mimetypes
53
import os
64
import platform
75
import tempfile
86
import time
97

10-
from six import python_2_unicode_compatible, string_types
11-
128
from django.core.files import File
139
from django.utils.encoding import force_str
1410
from django.utils.functional import cached_property
@@ -82,7 +78,7 @@ def sort_by_attr(self, seq, attr):
8278
the sorted list of objects.
8379
"""
8480
from operator import attrgetter
85-
if isinstance(attr, string_types): # Backward compatibility hack
81+
if isinstance(attr, str): # Backward compatibility hack
8682
attr = (attr, )
8783
return sorted(seq, key=attrgetter(*attr))
8884

@@ -200,7 +196,6 @@ def results_walk_filtered(self):
200196
return len(self.files_walk_filtered())
201197

202198

203-
@python_2_unicode_compatible
204199
class FileObject():
205200
"""
206201
The FileObject represents a file (or directory) on the server.

filebrowser/decorators.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
# coding: utf-8
2-
31
import os
42

53
from django.contrib import messages
64
from django.core.exceptions import ImproperlyConfigured
75
from django.http import HttpResponseRedirect
86
from django.urls import reverse
9-
from django.utils.encoding import smart_str
107
from django.utils.translation import gettext as _
118

129
from filebrowser.templatetags.fb_tags import query_helper
1310

1411

1512
def get_path(path, site):
16-
converted_path = smart_str(os.path.join(site.directory, path))
13+
converted_path = os.path.join(site.directory, path)
1714
if not path.startswith('.') and not os.path.isabs(converted_path):
1815
if site.storage.isdir(converted_path):
1916
return path
2017

2118

2219
def get_file(path, filename, site):
2320
# Files and directories are valid
24-
converted_path = smart_str(os.path.join(site.directory, path, filename))
21+
converted_path = os.path.join(site.directory, path, filename)
2522
if not path.startswith('.') and not filename.startswith('.') and not os.path.isabs(converted_path):
2623
if site.storage.isfile(converted_path) or site.storage.isdir(converted_path):
2724
return filename
@@ -38,7 +35,7 @@ def decorator(request, *args, **kwargs):
3835
if get_path(request.GET.get('dir', ''), site=site) is None:
3936
msg = _('The requested Folder does not exist.')
4037
messages.add_message(request, messages.ERROR, msg)
41-
redirect_url = reverse("filebrowser:fb_browse", current_app=site.name) + query_helper(request.GET, u"", "dir")
38+
redirect_url = reverse("filebrowser:fb_browse", current_app=site.name) + query_helper(request.GET, "", "dir")
4239
return HttpResponseRedirect(redirect_url)
4340
return function(request, *args, **kwargs)
4441
return decorator
@@ -52,7 +49,7 @@ def decorator(request, *args, **kwargs):
5249
if file_path is None:
5350
msg = _('The requested File does not exist.')
5451
messages.add_message(request, messages.ERROR, msg)
55-
redirect_url = reverse("filebrowser:fb_browse", current_app=site.name) + query_helper(request.GET, u"", "dir")
52+
redirect_url = reverse("filebrowser:fb_browse", current_app=site.name) + query_helper(request.GET, "", "dir")
5653
return HttpResponseRedirect(redirect_url)
5754
return function(request, *args, **kwargs)
5855
return decorator

filebrowser/fields.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import os
32

43
from django import forms
@@ -57,7 +56,7 @@ def render(self, name, value, attrs=None, renderer=None):
5756
class FileBrowseFormField(forms.CharField):
5857

5958
default_error_messages = {
60-
'extension': _(u'Extension %(ext)s is not allowed. Only %(allowed)s is allowed.'),
59+
'extension': _('Extension %(ext)s is not allowed. Only %(allowed)s is allowed.'),
6160
}
6261

6362
def __init__(self, max_length=None, min_length=None, site=None, directory=None, extensions=None, format=None, *args, **kwargs):
@@ -180,7 +179,7 @@ def render(self, name, value, attrs=None, renderer=None):
180179
class FileBrowseUploadFormField(forms.CharField):
181180

182181
default_error_messages = {
183-
'extension': _(u'Extension %(ext)s is not allowed. Only %(allowed)s is allowed.'),
182+
'extension': _('Extension %(ext)s is not allowed. Only %(allowed)s is allowed.'),
184183
}
185184

186185
def __init__(self, max_length=None, min_length=None, site=None, directory=None, extensions=None, format=None, upload_to=None, temp_upload_dir=None, *args, **kwargs):

filebrowser/forms.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# coding: utf-8
2-
31
import os
42
import re
53

@@ -13,12 +11,12 @@
1311
ALNUM_NAME_RE = re.compile(FOLDER_REGEX, re.U)
1412

1513
TRANSPOSE_CHOICES = (
16-
("", u"-----"),
17-
("0", _(u"Flip horizontal")),
18-
("1", _(u"Flip vertical")),
19-
("2", _(u"Rotate 90° CW")),
20-
("4", _(u"Rotate 90° CCW")),
21-
("3", _(u"Rotate 180°")),
14+
("", "-----"),
15+
("0", _("Flip horizontal")),
16+
("1", _("Flip vertical")),
17+
("2", _("Rotate 90° CW")),
18+
("4", _("Rotate 90° CCW")),
19+
("3", _("Rotate 180°")),
2220
)
2321

2422

@@ -27,7 +25,7 @@ class CreateDirForm(forms.Form):
2725
Form for creating a folder.
2826
"""
2927

30-
name = forms.CharField(widget=forms.TextInput(attrs=dict({'class': 'vTextField'}, max_length=50, min_length=3)), label=_(u'Name'), help_text=_(u'Only letters, numbers, underscores, spaces and hyphens are allowed.'), required=True)
28+
name = forms.CharField(widget=forms.TextInput(attrs=dict({'class': 'vTextField'}, max_length=50, min_length=3)), label=_('Name'), help_text=_('Only letters, numbers, underscores, spaces and hyphens are allowed.'), required=True)
3129

3230
def __init__(self, path, *args, **kwargs):
3331
self.path = path
@@ -39,10 +37,10 @@ def clean_name(self):
3937
if self.cleaned_data['name']:
4038
# only letters, numbers, underscores, spaces and hyphens are allowed.
4139
if not ALNUM_NAME_RE.search(self.cleaned_data['name']):
42-
raise forms.ValidationError(_(u'Only letters, numbers, underscores, spaces and hyphens are allowed.'))
40+
raise forms.ValidationError(_('Only letters, numbers, underscores, spaces and hyphens are allowed.'))
4341
# Folder must not already exist.
4442
if self.site.storage.isdir(os.path.join(self.path, convert_filename(self.cleaned_data['name']))):
45-
raise forms.ValidationError(_(u'The Folder already exists.'))
43+
raise forms.ValidationError(_('The Folder already exists.'))
4644
return convert_filename(self.cleaned_data['name'])
4745

4846

@@ -51,8 +49,8 @@ class ChangeForm(forms.Form):
5149
Form for renaming a file/folder.
5250
"""
5351

54-
custom_action = forms.ChoiceField(label=_(u'Actions'), required=False)
55-
name = forms.CharField(widget=forms.TextInput(attrs=dict({'class': 'vTextField'}, max_length=50, min_length=3)), label=_(u'Name'), help_text=_(u'Only letters, numbers, underscores, spaces and hyphens are allowed.'), required=True)
52+
custom_action = forms.ChoiceField(label=_('Actions'), required=False)
53+
name = forms.CharField(widget=forms.TextInput(attrs=dict({'class': 'vTextField'}, max_length=50, min_length=3)), label=_('Name'), help_text=_('Only letters, numbers, underscores, spaces and hyphens are allowed.'), required=True)
5654

5755
def __init__(self, *args, **kwargs):
5856
self.path = kwargs.pop("path", None)
@@ -61,7 +59,7 @@ def __init__(self, *args, **kwargs):
6159
super(ChangeForm, self).__init__(*args, **kwargs)
6260

6361
# Initialize choices of custom action
64-
choices = [("", u"-----")]
62+
choices = [("", "-----")]
6563
for name, action in self.site.applicable_actions(self.fileobject):
6664
choices.append((name, action.short_description))
6765
self.fields['custom_action'].choices = choices
@@ -71,10 +69,10 @@ def clean_name(self):
7169
if self.cleaned_data['name']:
7270
# only letters, numbers, underscores, spaces and hyphens are allowed.
7371
if not ALNUM_NAME_RE.search(self.cleaned_data['name']):
74-
raise forms.ValidationError(_(u'Only letters, numbers, underscores, spaces and hyphens are allowed.'))
72+
raise forms.ValidationError(_('Only letters, numbers, underscores, spaces and hyphens are allowed.'))
7573
# folder/file must not already exist.
7674
if self.site.storage.isdir(os.path.join(self.path, convert_filename(self.cleaned_data['name']))) and os.path.join(self.path, convert_filename(self.cleaned_data['name'])) != self.fileobject.path:
77-
raise forms.ValidationError(_(u'The Folder already exists.'))
75+
raise forms.ValidationError(_('The Folder already exists.'))
7876
elif self.site.storage.isfile(os.path.join(self.path, convert_filename(self.cleaned_data['name']))) and os.path.join(self.path, convert_filename(self.cleaned_data['name'])) != self.fileobject.path:
79-
raise forms.ValidationError(_(u'The File already exists.'))
77+
raise forms.ValidationError(_('The File already exists.'))
8078
return convert_filename(self.cleaned_data['name'])

filebrowser/management/commands/fb_version_generate.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
# coding: utf-8
2-
31
import os
42
import re
53

6-
from six.moves import input
7-
84
from django.conf import settings
95
from django.core.management.base import BaseCommand, CommandError
106
from filebrowser.base import FileListing

filebrowser/management/commands/fb_version_remove.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# coding: utf-8
21
import os
32
import re
43
import sys
54

6-
from six.moves import input
7-
85
from django.conf import settings
96
from django.core.management.base import BaseCommand, CommandError
107
from filebrowser.settings import EXCLUDE, EXTENSIONS

filebrowser/namers.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
from __future__ import unicode_literals
2-
31
import re
42

5-
import six
6-
73
from django.utils.encoding import force_str
84
from django.utils.module_loading import import_string
95

@@ -15,7 +11,7 @@ def get_namer(**kwargs):
1511
return namer_cls(**kwargs)
1612

1713

18-
class VersionNamer(object):
14+
class VersionNamer:
1915
"Base namer only for reference"
2016

2117
def __init__(self, **kwargs):
@@ -88,11 +84,11 @@ def options_list(self):
8884
if v is True:
8985
opts.append(k)
9086
continue
91-
if not isinstance(v, six.string_types):
87+
if not isinstance(v, str):
9288
try:
93-
v = 'x'.join([six.text_type(v) for item in v])
89+
v = 'x'.join([str(v) for item in v])
9490
except TypeError:
95-
v = six.text_type(v)
91+
v = str(v)
9692
opts.append('%s-%s' % (k, v))
9793

9894
return opts

0 commit comments

Comments
 (0)