diff --git a/docs/conf.py b/docs/conf.py index c9fbffcdb..70ad82869 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Django FileBrowser documentation build configuration file, created by # sphinx-quickstart on Sun Dec 5 19:11:46 2010. # @@ -43,8 +41,8 @@ master_doc = 'index' # General information about the project. -project = u'Django FileBrowser' -copyright = u'2022, Patrick Kranzlmueller' +project = 'Django FileBrowser' +copyright = '2022, Patrick Kranzlmueller' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -182,8 +180,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'DjangoFileBrowser.tex', u'Django FileBrowser Documentation', - u'Patrick Kranzlmueller', 'manual'), + ('index', 'DjangoFileBrowser.tex', 'Django FileBrowser Documentation', + 'Patrick Kranzlmueller', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -215,8 +213,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'djangofilebrowser', u'Django FileBrowser Documentation', - [u'Patrick Kranzlmueller'], 1) + ('index', 'djangofilebrowser', 'Django FileBrowser Documentation', + ['Patrick Kranzlmueller'], 1) ] if not on_rtd: # only import and set the theme if we're building docs locally diff --git a/docs/fieldswidgets.rst b/docs/fieldswidgets.rst index 07e8bce2e..0784e2bce 100644 --- a/docs/fieldswidgets.rst +++ b/docs/fieldswidgets.rst @@ -90,7 +90,7 @@ Return a :ref:`fileobject` from a `FileField " % (csrf_token)) + return mark_safe("
" % (csrf_token)) else: # It's very probable that the token is missing because of # misconfiguration, so we raise a warning @@ -22,7 +20,7 @@ def render(self, context): if settings.DEBUG: import warnings warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.") - return u'' + return '' def fb_csrf_token(parser, token): diff --git a/filebrowser/templatetags/fb_pagination.py b/filebrowser/templatetags/fb_pagination.py index 771686800..a03d0b288 100644 --- a/filebrowser/templatetags/fb_pagination.py +++ b/filebrowser/templatetags/fb_pagination.py @@ -1,5 +1,3 @@ -# coding: utf-8 - from django.template import Library diff --git a/filebrowser/templatetags/fb_tags.py b/filebrowser/templatetags/fb_tags.py index 1aa76f574..5691b489d 100644 --- a/filebrowser/templatetags/fb_tags.py +++ b/filebrowser/templatetags/fb_tags.py @@ -1,5 +1,3 @@ -# coding: utf-8 - from urllib.parse import quote as urlquote from django import template @@ -61,7 +59,7 @@ def get_query_string(p, new_params=None, remove=None): del p[k] elif v is not None: p[k] = v - return '?' + '&'.join([u'%s=%s' % (urlquote(k), urlquote(v)) for k, v in p.items()]) + return '?' + '&'.join(['%s=%s' % (urlquote(k), urlquote(v)) for k, v in p.items()]) def string_to_dict(string): diff --git a/filebrowser/templatetags/fb_versions.py b/filebrowser/templatetags/fb_versions.py index 79478d605..d9a6929c6 100644 --- a/filebrowser/templatetags/fb_versions.py +++ b/filebrowser/templatetags/fb_versions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - from django.conf import settings from django.core.files import File from django.template import Library, Node, Variable, VariableDoesNotExist, TemplateSyntaxError diff --git a/filebrowser/utils.py b/filebrowser/utils.py index 7c491d5b5..8594b86e9 100644 --- a/filebrowser/utils.py +++ b/filebrowser/utils.py @@ -1,12 +1,8 @@ -# coding: utf-8 - import math import os import re import unicodedata -import six - from django.utils.module_loading import import_string from filebrowser.settings import (CONVERT_FILENAME, NORMALIZE_FILENAME, STRICT_PIL, VERSION_PROCESSORS) @@ -29,7 +25,7 @@ def convert_filename(value): chunks = value.split(os.extsep) normalized = [] for v in chunks: - v = unicodedata.normalize('NFKD', six.text_type(v)).encode('ascii', 'ignore').decode('ascii') + v = unicodedata.normalize('NFKD', str(v)).encode('ascii', 'ignore').decode('ascii') v = re.sub(r'[^\w\s-]', '', v).strip() normalized.append(v) diff --git a/requirements.txt b/requirements.txt index ce7c767b6..423c2549b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ django-grappelli>=3.0,<3.1 pillow -six diff --git a/setup.py b/setup.py index e79587cca..6e4d66f19 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,5 @@ def read(fname): install_requires=[ 'django-grappelli>=3.0,<3.1', 'pillow', - 'six', ], ) diff --git a/tests/requirements.txt b/tests/requirements.txt index 9b6b24acb..e3bf4a58e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,8 +1,6 @@ Django>=4.0,<4.1 django-grappelli>=3.0,<3.1 funcsigs==1.0.2 -mock==4.0.3 pbr==5.8.0 Pillow==9.3.0 -six==1.16.0 wheel==0.37.1 diff --git a/tests/test_base.py b/tests/test_base.py index 04fd8da13..74ab2f072 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,16 +1,14 @@ -# coding: utf-8 - import ntpath import os import posixpath import shutil +from unittest.mock import patch from filebrowser.base import FileListing, FileObject from filebrowser.settings import VERSIONS from filebrowser.sites import site -from mock import patch -from tests import FilebrowserTestCase as TestCase +from . import FilebrowserTestCase as TestCase class FileObjectPathTests(TestCase): @@ -70,7 +68,7 @@ def test_posix_paths(self): @patch('filebrowser.namers.VERSION_NAMER', 'filebrowser.namers.OptionsNamer') def test_unicode_options_namer_version(self): path_unicode = os.path.join(self.FOLDER_PATH, '測試文件.jpg') - expected = u'測試文件_large--680x0.jpg' + expected = '測試文件_large--680x0.jpg' shutil.copy(self.STATIC_IMG_PATH, path_unicode) f = FileObject(path_unicode, site=site) @@ -394,9 +392,9 @@ def test_listing(self): """ self.assertEqual(self.F_LISTING_IMAGE.listing(), []) - self.assertEqual(list(self.F_LISTING_FOLDER.listing()), [u'folder', u'testimage.jpg']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder']) + self.assertEqual(list(self.F_LISTING_FOLDER.listing()), ['folder', 'testimage.jpg']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), ['_test/uploads/testimage.jpg', '_test/uploads/folder']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), ['_test/uploads/testimage.jpg', '_test/uploads/folder']) self.assertEqual(self.F_LISTING_FOLDER.results_listing_total(), 2) self.assertEqual(self.F_LISTING_FOLDER.results_listing_filtered(), 2) @@ -412,9 +410,9 @@ def test_listing_filtered(self): """ self.assertEqual(self.F_LISTING_IMAGE.listing(), []) - self.assertEqual(list(self.F_LISTING_FOLDER.listing()), [u'folder', u'testimage.jpg']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder']) + self.assertEqual(list(self.F_LISTING_FOLDER.listing()), ['folder', 'testimage.jpg']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), ['_test/uploads/testimage.jpg', '_test/uploads/folder']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), ['_test/uploads/testimage.jpg', '_test/uploads/folder']) self.assertEqual(self.F_LISTING_FOLDER.results_listing_total(), 2) self.assertEqual(self.F_LISTING_FOLDER.results_listing_filtered(), 2) @@ -430,9 +428,9 @@ def test_walk(self): """ self.assertEqual(self.F_LISTING_IMAGE.walk(), []) - self.assertEqual(list(self.F_LISTING_FOLDER.walk()), [u'folder/subfolder/testimage.jpg', u'folder/subfolder', u'folder', u'testimage.jpg']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder', u'_test/uploads/folder/subfolder', u'_test/uploads/folder/subfolder/testimage.jpg']) - self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder', u'_test/uploads/folder/subfolder', u'_test/uploads/folder/subfolder/testimage.jpg']) + self.assertEqual(list(self.F_LISTING_FOLDER.walk()), ['folder/subfolder/testimage.jpg', 'folder/subfolder', 'folder', 'testimage.jpg']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_total()), ['_test/uploads/testimage.jpg', '_test/uploads/folder', '_test/uploads/folder/subfolder', '_test/uploads/folder/subfolder/testimage.jpg']) + self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_filtered()), ['_test/uploads/testimage.jpg', '_test/uploads/folder', '_test/uploads/folder/subfolder', '_test/uploads/folder/subfolder/testimage.jpg']) self.assertEqual(self.F_LISTING_FOLDER.results_walk_total(), 4) self.assertEqual(self.F_LISTING_FOLDER.results_walk_filtered(), 4) diff --git a/tests/test_commands.py b/tests/test_commands.py index fef0f37e9..1e358697f 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,15 +1,12 @@ -# coding: utf-8 - import os import shutil import sys - -from six import StringIO +from io import StringIO from django.conf import settings from django.core.management import call_command from filebrowser.settings import DIRECTORY -from tests import FilebrowserTestCase as TestCase +from . import FilebrowserTestCase as TestCase class VersionGenerateCommandTests(TestCase): diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 48d4219ae..ad996722e 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1,10 +1,8 @@ -# coding: utf-8 - import shutil from filebrowser.decorators import get_path, get_file from filebrowser.sites import site -from tests import FilebrowserTestCase as TestCase +from . import FilebrowserTestCase as TestCase class GetPathTests(TestCase): diff --git a/tests/test_namers.py b/tests/test_namers.py index 79cc4d1e2..2e2d9f7b7 100644 --- a/tests/test_namers.py +++ b/tests/test_namers.py @@ -1,13 +1,9 @@ -# coding: utf-8 - import shutil - -from mock import patch - -from filebrowser.settings import VERSIONS -from tests import FilebrowserTestCase as TestCase +from unittest.mock import patch from filebrowser.namers import OptionsNamer +from filebrowser.settings import VERSIONS +from . import FilebrowserTestCase as TestCase class BaseNamerTests(TestCase): diff --git a/tests/test_settings.py b/tests/test_settings.py index dcf997dcf..3597985a6 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,3 @@ -# coding: utf-8 - # FIXME # These tests are designed to run against production, not testing. They # would be better suited for the Django Check Framework. diff --git a/tests/test_sites.py b/tests/test_sites.py index 3dc39b19c..b95865a14 100644 --- a/tests/test_sites.py +++ b/tests/test_sites.py @@ -1,20 +1,15 @@ -# coding: utf-8 -from __future__ import with_statement import os import json import shutil +from unittest.mock import patch from django.urls import reverse -try: - from django.utils.six.moves.urllib.parse import urlencode -except: - from django.utils.http import urlencode -from mock import patch +from django.utils.http import urlencode from filebrowser.settings import VERSIONS, DEFAULT_PERMISSIONS from filebrowser.base import FileObject from filebrowser.sites import site -from tests import FilebrowserTestCase as TestCase +from . import FilebrowserTestCase as TestCase class BrowseViewTests(TestCase): @@ -34,7 +29,7 @@ def test_get(self): def test_filter(self): shutil.copy(self.STATIC_IMG_PATH, self.FOLDER_PATH) - self.assertEqual(site.storage.listdir(self.F_FOLDER.path), (['subfolder'], [u'testimage.jpg'])) + self.assertEqual(site.storage.listdir(self.F_FOLDER.path), (['subfolder'], ['testimage.jpg'])) response = self.client.get(self.url + "?dir=folder") self.assertEqual(len(response.context['page'].object_list), 2) @@ -166,19 +161,19 @@ def test_do_temp_upload(self): @patch('filebrowser.sites.OVERWRITE_EXISTING', True) def test_overwrite_existing_true(self): shutil.copy(self.STATIC_IMG_PATH, self.SUBFOLDER_PATH) - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'testimage.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['testimage.jpg'])) url = '?'.join([self.url, urlencode({'folder': self.F_SUBFOLDER.path_relative_directory})]) with open(self.STATIC_IMG_PATH, "rb") as f: self.client.post(url, data={'qqfile': 'testimage.jpg', 'file': f}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'testimage.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['testimage.jpg'])) @patch('filebrowser.sites.OVERWRITE_EXISTING', False) def test_overwrite_existing_false(self): shutil.copy(self.STATIC_IMG_PATH, self.SUBFOLDER_PATH) - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'testimage.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['testimage.jpg'])) url = '?'.join([self.url, urlencode({'folder': self.F_SUBFOLDER.path_relative_directory})]) @@ -192,28 +187,28 @@ def test_overwrite_existing_false(self): def test_convert_false_normalize_false(self): with open(self.STATIC_IMG_BAD_NAME_PATH, "rb") as f: self.client.post(self.url_bad_name, data={'qqfile': 'TEST_IMAGE_000.jpg', 'file': f}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'TEST_IMAGE_000.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['TEST_IMAGE_000.jpg'])) @patch('filebrowser.utils.CONVERT_FILENAME', True) @patch('filebrowser.utils.NORMALIZE_FILENAME', False) def test_convert_true_normalize_false(self): with open(self.STATIC_IMG_BAD_NAME_PATH, "rb") as f: self.client.post(self.url_bad_name, data={'qqfile': 'TEST_IMAGE_000.jpg', 'file': f}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'test_image_000.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['test_image_000.jpg'])) @patch('filebrowser.utils.CONVERT_FILENAME', False) @patch('filebrowser.utils.NORMALIZE_FILENAME', True) def test_convert_false_normalize_true(self): with open(self.STATIC_IMG_BAD_NAME_PATH, "rb") as f: self.client.post(self.url_bad_name, data={'qqfile': 'TEST_IMAGE_000.jpg', 'file': f}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'TEST_IMAGE_000.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['TEST_IMAGE_000.jpg'])) @patch('filebrowser.utils.CONVERT_FILENAME', True) @patch('filebrowser.utils.NORMALIZE_FILENAME', True) def test_convert_true_normalize_true(self): with open(self.STATIC_IMG_BAD_NAME_PATH, "rb") as f: self.client.post(self.url_bad_name, data={'qqfile': 'TEST_IMAGE_000.jpg', 'file': f}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], [u'test_image_000.jpg'])) + self.assertEqual(site.storage.listdir(self.F_SUBFOLDER.path), ([], ['test_image_000.jpg'])) class DetailViewTests(TestCase): diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index f62ed414b..17fc0a160 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1,4 +1,3 @@ -# coding: utf-8 from django.test import TestCase from django.http import QueryDict diff --git a/tests/test_versions.py b/tests/test_versions.py index 3b32ff839..00f3716ae 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -1,15 +1,14 @@ -# coding: utf-8 import os import shutil +from unittest.mock import patch from django.conf import settings from django.template import Context, Template, TemplateSyntaxError -from mock import patch -from tests import FilebrowserTestCase as TestCase from filebrowser.settings import STRICT_PIL from filebrowser import utils from filebrowser.utils import scale_and_crop, process_image +from . import FilebrowserTestCase as TestCase if STRICT_PIL: from PIL import Image