From 0ab18e78b008c5c4ec494ce73689b27d08dd9972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Mon, 5 Aug 2024 10:51:17 +0200 Subject: [PATCH] Run pre-commit on all files --- CONTRIBUTING.rst | 2 +- demo/README.rst | 2 +- demo/demoproject/apache/tests.py | 2 +- demo/demoproject/apache/urls.py | 1 + demo/demoproject/apache/views.py | 2 +- demo/demoproject/fixtures/demo.json | 6 +++--- demo/demoproject/lighttpd/tests.py | 2 +- demo/demoproject/lighttpd/urls.py | 1 + demo/demoproject/lighttpd/views.py | 2 +- demo/demoproject/nginx/tests.py | 2 +- demo/demoproject/nginx/views.py | 2 +- demo/demoproject/settings.py | 1 + demo/demoproject/storage/tests.py | 5 ++--- demo/demoproject/tests.py | 1 + demo/demoproject/wsgi.py | 1 + django_downloadview/__init__.py | 1 + django_downloadview/apache/__init__.py | 1 + django_downloadview/apache/decorators.py | 1 + django_downloadview/apache/response.py | 7 +++++-- django_downloadview/api.py | 1 + django_downloadview/files.py | 1 + django_downloadview/io.py | 1 + django_downloadview/lighttpd/__init__.py | 1 + django_downloadview/lighttpd/decorators.py | 1 + django_downloadview/lighttpd/response.py | 7 +++++-- django_downloadview/middlewares.py | 11 ++++++----- django_downloadview/nginx/__init__.py | 1 + django_downloadview/nginx/decorators.py | 1 + django_downloadview/nginx/response.py | 3 ++- django_downloadview/nginx/settings.py | 1 + django_downloadview/response.py | 4 ++-- django_downloadview/shortcuts.py | 1 + django_downloadview/utils.py | 1 + django_downloadview/views/__init__.py | 1 + django_downloadview/views/base.py | 3 ++- django_downloadview/views/http.py | 3 ++- django_downloadview/views/object.py | 1 + django_downloadview/views/path.py | 1 + django_downloadview/views/storage.py | 1 + django_downloadview/views/virtual.py | 1 + docs/conf.py | 4 ++-- docs/files.txt | 2 +- docs/optimizations/nginx.txt | 6 +++--- docs/overview.txt | 2 +- docs/testing.txt | 1 - setup.py | 8 ++++---- tests/api.py | 1 + tests/io.py | 1 + tests/packaging.py | 1 + tests/response.py | 10 ++++------ tests/sendfile.py | 1 + tests/views.py | 1 + 52 files changed, 80 insertions(+), 46 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 0c4c5d4..8533576 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -92,7 +92,7 @@ documentation. Maintain it along with code and documentation. .. target-notes:: -.. _`bugtracker`: +.. _`bugtracker`: https://github.com/jazzband/django-downloadview/issues .. _`rebase`: http://git-scm.com/book/en/Git-Branching-Rebasing .. _`merge-based rebase`: https://tech.people-doc.com/psycho-rebasing.html diff --git a/demo/README.rst b/demo/README.rst index bebf318..c6702f1 100644 --- a/demo/README.rst +++ b/demo/README.rst @@ -32,7 +32,7 @@ Deploy the demo System requirements: * `Python`_ version 3.7+, available as ``python`` command. - + .. note:: You may use `Virtualenv`_ to make sure the active ``python`` is the right diff --git a/demo/demoproject/apache/tests.py b/demo/demoproject/apache/tests.py index e3afbbc..e812ed2 100644 --- a/demo/demoproject/apache/tests.py +++ b/demo/demoproject/apache/tests.py @@ -58,4 +58,4 @@ def test_response(self): basename="hello-world.txt", file_path="/apache-modified-headers/hello-world.txt", ) - self.assertEqual(response['X-Test'], 'header') + self.assertEqual(response["X-Test"], "header") diff --git a/demo/demoproject/apache/urls.py b/demo/demoproject/apache/urls.py index 8994f8c..7fcb1ae 100644 --- a/demo/demoproject/apache/urls.py +++ b/demo/demoproject/apache/urls.py @@ -1,4 +1,5 @@ """URL mapping.""" + from django.urls import path from demoproject.apache import views diff --git a/demo/demoproject/apache/views.py b/demo/demoproject/apache/views.py index 00df043..875c9f3 100644 --- a/demo/demoproject/apache/views.py +++ b/demo/demoproject/apache/views.py @@ -27,7 +27,7 @@ def _modified_headers(request): view = StorageDownloadView.as_view(storage=storage, path="hello-world.txt") response = view(request) - response["X-Test"] = 'header' + response["X-Test"] = "header" return response diff --git a/demo/demoproject/fixtures/demo.json b/demo/demoproject/fixtures/demo.json index 0424b6c..bb14d6b 100644 --- a/demo/demoproject/fixtures/demo.json +++ b/demo/demoproject/fixtures/demo.json @@ -1,9 +1,9 @@ [ { - "pk": 1, - "model": "object.document", + "pk": 1, + "model": "object.document", "fields": { - "slug": "hello-world", + "slug": "hello-world", "file": "object/hello-world.txt" } } diff --git a/demo/demoproject/lighttpd/tests.py b/demo/demoproject/lighttpd/tests.py index 97b9d84..4e5fe90 100644 --- a/demo/demoproject/lighttpd/tests.py +++ b/demo/demoproject/lighttpd/tests.py @@ -58,4 +58,4 @@ def test_response(self): basename="hello-world.txt", file_path="/lighttpd-modified-headers/hello-world.txt", ) - self.assertEqual(response['X-Test'], 'header') + self.assertEqual(response["X-Test"], "header") diff --git a/demo/demoproject/lighttpd/urls.py b/demo/demoproject/lighttpd/urls.py index 40c58f2..406cfe9 100644 --- a/demo/demoproject/lighttpd/urls.py +++ b/demo/demoproject/lighttpd/urls.py @@ -1,4 +1,5 @@ """URL mapping.""" + from django.urls import path from demoproject.lighttpd import views diff --git a/demo/demoproject/lighttpd/views.py b/demo/demoproject/lighttpd/views.py index 8f5a4c0..2b2d4ec 100644 --- a/demo/demoproject/lighttpd/views.py +++ b/demo/demoproject/lighttpd/views.py @@ -27,7 +27,7 @@ def _modified_headers(request): view = StorageDownloadView.as_view(storage=storage, path="hello-world.txt") response = view(request) - response["X-Test"] = 'header' + response["X-Test"] = "header" return response diff --git a/demo/demoproject/nginx/tests.py b/demo/demoproject/nginx/tests.py index 1f38f5a..22a3c55 100644 --- a/demo/demoproject/nginx/tests.py +++ b/demo/demoproject/nginx/tests.py @@ -70,4 +70,4 @@ def test_response(self): with_buffering=None, limit_rate=None, ) - self.assertEqual(response['X-Test'], 'header') + self.assertEqual(response["X-Test"], "header") diff --git a/demo/demoproject/nginx/views.py b/demo/demoproject/nginx/views.py index e293b1e..01364f1 100644 --- a/demo/demoproject/nginx/views.py +++ b/demo/demoproject/nginx/views.py @@ -27,7 +27,7 @@ def _modified_headers(request): view = StorageDownloadView.as_view(storage=storage, path="hello-world.txt") response = view(request) - response["X-Test"] = 'header' + response["X-Test"] = "header" return response diff --git a/demo/demoproject/settings.py b/demo/demoproject/settings.py index 87e4bc4..f14aba7 100644 --- a/demo/demoproject/settings.py +++ b/demo/demoproject/settings.py @@ -1,4 +1,5 @@ """Django settings for django-downloadview demo project.""" + import os diff --git a/demo/demoproject/storage/tests.py b/demo/demoproject/storage/tests.py index f6e6773..3a56643 100644 --- a/demo/demoproject/storage/tests.py +++ b/demo/demoproject/storage/tests.py @@ -44,8 +44,7 @@ def test_not_modified_download_response(self): url = reverse("storage:static_path", kwargs={"path": "1.txt"}) year = datetime.date.today().year + 4 response = self.client.get( - url, - HTTP_IF_MODIFIED_SINCE=f"Sat, 29 Oct {year} 19:43:31 GMT", + url, headers={"if-modified-since": f"Sat, 29 Oct {year} 19:43:31 GMT"} ) self.assertTrue(isinstance(response, HttpResponseNotModified)) @@ -55,7 +54,7 @@ def test_modified_since_download_response(self): setup_file("1.txt") url = reverse("storage:static_path", kwargs={"path": "1.txt"}) response = self.client.get( - url, HTTP_IF_MODIFIED_SINCE="Sat, 29 Oct 1980 19:43:31 GMT" + url, headers={"if-modified-since": "Sat, 29 Oct 1980 19:43:31 GMT"} ) assert_download_response( self, diff --git a/demo/demoproject/tests.py b/demo/demoproject/tests.py index 56864bb..eb64347 100644 --- a/demo/demoproject/tests.py +++ b/demo/demoproject/tests.py @@ -1,4 +1,5 @@ """Test suite for demoproject.download.""" + from django.test import TestCase from django.urls import reverse diff --git a/demo/demoproject/wsgi.py b/demo/demoproject/wsgi.py index 9beca42..c5d8444 100755 --- a/demo/demoproject/wsgi.py +++ b/demo/demoproject/wsgi.py @@ -12,6 +12,7 @@ framework. """ + import os from django.core.wsgi import get_wsgi_application diff --git a/django_downloadview/__init__.py b/django_downloadview/__init__.py index cfbe9cb..e399dd9 100644 --- a/django_downloadview/__init__.py +++ b/django_downloadview/__init__.py @@ -1,4 +1,5 @@ """Serve files with Django and reverse proxies.""" + from django_downloadview.api import * # NoQA import importlib.metadata diff --git a/django_downloadview/apache/__init__.py b/django_downloadview/apache/__init__.py index 478dd35..20cca9a 100644 --- a/django_downloadview/apache/__init__.py +++ b/django_downloadview/apache/__init__.py @@ -5,6 +5,7 @@ Apache optimizations `. """ + # API shortcuts. from django_downloadview.apache.decorators import x_sendfile # NoQA from django_downloadview.apache.middlewares import XSendfileMiddleware # NoQA diff --git a/django_downloadview/apache/decorators.py b/django_downloadview/apache/decorators.py index dda7890..04ad473 100644 --- a/django_downloadview/apache/decorators.py +++ b/django_downloadview/apache/decorators.py @@ -1,4 +1,5 @@ """Decorators to apply Apache X-Sendfile on a specific view.""" + from django_downloadview.apache.middlewares import XSendfileMiddleware from django_downloadview.decorators import DownloadDecorator diff --git a/django_downloadview/apache/response.py b/django_downloadview/apache/response.py index 94b1132..dc5809e 100644 --- a/django_downloadview/apache/response.py +++ b/django_downloadview/apache/response.py @@ -1,4 +1,5 @@ """Apache's specific responses.""" + import os.path from django_downloadview.response import ProxiedDownloadResponse, content_disposition @@ -7,11 +8,13 @@ class XSendfileResponse(ProxiedDownloadResponse): "Delegates serving file to Apache via X-Sendfile header." - def __init__(self, file_path, content_type, basename=None, attachment=True, headers=None): + def __init__( + self, file_path, content_type, basename=None, attachment=True, headers=None + ): """Return a HttpResponse with headers for Apache X-Sendfile.""" # content-type must be provided only as keyword argument to response if headers and content_type: - headers.pop('Content-Type', None) + headers.pop("Content-Type", None) super().__init__(content_type=content_type, headers=headers) if attachment: self.basename = basename or os.path.basename(file_path) diff --git a/django_downloadview/api.py b/django_downloadview/api.py index bc0d3c7..8c69017 100644 --- a/django_downloadview/api.py +++ b/django_downloadview/api.py @@ -1,5 +1,6 @@ # flake8: noqa """Declaration of API shortcuts.""" + from django_downloadview.files import HTTPFile, StorageFile, VirtualFile from django_downloadview.io import BytesIteratorIO, TextIteratorIO from django_downloadview.middlewares import ( diff --git a/django_downloadview/files.py b/django_downloadview/files.py index 5341bbe..b71a4dd 100644 --- a/django_downloadview/files.py +++ b/django_downloadview/files.py @@ -1,4 +1,5 @@ """File wrappers for use as exchange data between views and responses.""" + from io import BytesIO from urllib.parse import urlparse diff --git a/django_downloadview/io.py b/django_downloadview/io.py index b1d1778..acd1eab 100644 --- a/django_downloadview/io.py +++ b/django_downloadview/io.py @@ -1,4 +1,5 @@ """Low-level IO operations, for use with file wrappers.""" + import io from django.utils.encoding import force_bytes, force_str diff --git a/django_downloadview/lighttpd/__init__.py b/django_downloadview/lighttpd/__init__.py index fb2c7df..793a546 100644 --- a/django_downloadview/lighttpd/__init__.py +++ b/django_downloadview/lighttpd/__init__.py @@ -6,6 +6,7 @@ `. """ + # API shortcuts. from django_downloadview.lighttpd.decorators import x_sendfile # NoQA from django_downloadview.lighttpd.middlewares import XSendfileMiddleware # NoQA diff --git a/django_downloadview/lighttpd/decorators.py b/django_downloadview/lighttpd/decorators.py index f55459e..29b58e7 100644 --- a/django_downloadview/lighttpd/decorators.py +++ b/django_downloadview/lighttpd/decorators.py @@ -1,4 +1,5 @@ """Decorators to apply Lighttpd X-Sendfile on a specific view.""" + from django_downloadview.decorators import DownloadDecorator from django_downloadview.lighttpd.middlewares import XSendfileMiddleware diff --git a/django_downloadview/lighttpd/response.py b/django_downloadview/lighttpd/response.py index 97cc8b4..1f5542a 100644 --- a/django_downloadview/lighttpd/response.py +++ b/django_downloadview/lighttpd/response.py @@ -1,4 +1,5 @@ """Lighttpd's specific responses.""" + import os.path from django_downloadview.response import ProxiedDownloadResponse, content_disposition @@ -7,11 +8,13 @@ class XSendfileResponse(ProxiedDownloadResponse): "Delegates serving file to Lighttpd via X-Sendfile header." - def __init__(self, file_path, content_type, basename=None, attachment=True, headers=None): + def __init__( + self, file_path, content_type, basename=None, attachment=True, headers=None + ): """Return a HttpResponse with headers for Lighttpd X-Sendfile.""" # content-type must be porvided only as keyword argument to response if headers and content_type: - headers.pop('Content-Type', None) + headers.pop("Content-Type", None) super().__init__(content_type=content_type, headers=headers) if attachment: self.basename = basename or os.path.basename(file_path) diff --git a/django_downloadview/middlewares.py b/django_downloadview/middlewares.py index e877fb3..ef8f9c0 100644 --- a/django_downloadview/middlewares.py +++ b/django_downloadview/middlewares.py @@ -4,6 +4,7 @@ responses and may replace them with optimized download responses. """ + import collections.abc import copy import os @@ -36,6 +37,7 @@ class BaseDownloadMiddleware: Subclasses **must** implement :py:meth:`process_download_response` method. """ + def __init__(self, get_response): self.get_response = get_response @@ -75,9 +77,8 @@ def is_download_response(self, response): whose file attribute have either an URL or a file name. """ - return ( - super().is_download_response(response) - and bool(getattr(response.file, 'url', None) or getattr(response.file, 'name', None)) + return super().is_download_response(response) and bool( + getattr(response.file, "url", None) or getattr(response.file, "name", None) ) @@ -91,7 +92,7 @@ def __init__(self, middlewares=AUTO_CONFIGURE): def auto_configure_middlewares(self): """Populate :attr:`middlewares` from ``settings.DOWNLOADVIEW_MIDDLEWARES``.""" - for (key, import_string, kwargs) in getattr( + for key, import_string, kwargs in getattr( settings, "DOWNLOADVIEW_MIDDLEWARES", [] ): factory = import_member(import_string) @@ -100,7 +101,7 @@ def auto_configure_middlewares(self): def dispatch(self, request, response): """Dispatches job to children middlewares.""" - for (key, middleware) in self.middlewares: + for key, middleware in self.middlewares: response = middleware.process_response(request, response) return response diff --git a/django_downloadview/nginx/__init__.py b/django_downloadview/nginx/__init__.py index 7e420f8..cb2fac4 100644 --- a/django_downloadview/nginx/__init__.py +++ b/django_downloadview/nginx/__init__.py @@ -5,6 +5,7 @@ `. """ + # API shortcuts. from django_downloadview.nginx.decorators import x_accel_redirect # NoQA from django_downloadview.nginx.middlewares import XAccelRedirectMiddleware # NoQA diff --git a/django_downloadview/nginx/decorators.py b/django_downloadview/nginx/decorators.py index 0a7f3a9..11fda2b 100644 --- a/django_downloadview/nginx/decorators.py +++ b/django_downloadview/nginx/decorators.py @@ -1,4 +1,5 @@ """Decorators to apply Nginx X-Accel on a specific view.""" + from django_downloadview.decorators import DownloadDecorator from django_downloadview.nginx.middlewares import XAccelRedirectMiddleware diff --git a/django_downloadview/nginx/response.py b/django_downloadview/nginx/response.py index d789b64..cbebf15 100644 --- a/django_downloadview/nginx/response.py +++ b/django_downloadview/nginx/response.py @@ -1,4 +1,5 @@ """Nginx's specific responses.""" + from datetime import timedelta from django.utils.timezone import now @@ -24,7 +25,7 @@ def __init__( """Return a HttpResponse with headers for Nginx X-Accel-Redirect.""" # content-type must be porvided only as keyword argument to response if headers and content_type: - headers.pop('Content-Type', None) + headers.pop("Content-Type", None) super().__init__(content_type=content_type, headers=headers) if attachment: self.basename = basename or url_basename(redirect_url, content_type) diff --git a/django_downloadview/nginx/settings.py b/django_downloadview/nginx/settings.py index 6416d40..28e866c 100644 --- a/django_downloadview/nginx/settings.py +++ b/django_downloadview/nginx/settings.py @@ -7,6 +7,7 @@ for details. """ + import warnings from django.conf import settings diff --git a/django_downloadview/response.py b/django_downloadview/response.py index 6648aaa..cedc3c7 100644 --- a/django_downloadview/response.py +++ b/django_downloadview/response.py @@ -1,4 +1,5 @@ """:py:class:`django.http.HttpResponse` subclasses.""" + import mimetypes import os import re @@ -77,11 +78,10 @@ def content_disposition(filename): # which can permit a reflected file download attack. The UTF-8 # version is immune because it's not quoted. ascii_filename = ( - encode_basename_ascii(filename).replace("\\", "\\\\").replace('"', r'\"') + encode_basename_ascii(filename).replace("\\", "\\\\").replace('"', r"\"") ) utf8_filename = encode_basename_utf8(filename) if ascii_filename == utf8_filename: # ASCII only. - return f'attachment; filename="{ascii_filename}"' else: return ( diff --git a/django_downloadview/shortcuts.py b/django_downloadview/shortcuts.py index 780c507..1f346f4 100644 --- a/django_downloadview/shortcuts.py +++ b/django_downloadview/shortcuts.py @@ -1,4 +1,5 @@ """Port of django-sendfile in django-downloadview.""" + from django_downloadview.views.path import PathDownloadView diff --git a/django_downloadview/utils.py b/django_downloadview/utils.py index 2354e18..f3ea739 100644 --- a/django_downloadview/utils.py +++ b/django_downloadview/utils.py @@ -1,4 +1,5 @@ """Utility functions that may be implemented in external packages.""" + import re charset_pattern = re.compile(r"charset=(?P.+)$", re.I | re.U) diff --git a/django_downloadview/views/__init__.py b/django_downloadview/views/__init__.py index 9a78444..7d00ed0 100644 --- a/django_downloadview/views/__init__.py +++ b/django_downloadview/views/__init__.py @@ -1,4 +1,5 @@ """Views to stream files.""" + # API shortcuts. from django_downloadview.views.base import BaseDownloadView, DownloadMixin # NoQA from django_downloadview.views.http import HTTPDownloadView # NoQA diff --git a/django_downloadview/views/base.py b/django_downloadview/views/base.py index c01872c..3c5abb2 100644 --- a/django_downloadview/views/base.py +++ b/django_downloadview/views/base.py @@ -1,5 +1,6 @@ """Base material for download views: :class:`DownloadMixin` and :class:`BaseDownloadView`""" + import calendar from django.http import Http404, HttpResponseNotModified @@ -156,7 +157,7 @@ def render_to_response(self, *response_args, **response_kwargs): except exceptions.FileNotFound: return self.file_not_found_response() # Respect the If-Modified-Since header. - since = self.request.META.get("HTTP_IF_MODIFIED_SINCE", None) + since = self.request.headers.get("if-modified-since", None) if since is not None: if not self.was_modified_since(self.file_instance, since): return self.not_modified_response(**response_kwargs) diff --git a/django_downloadview/views/http.py b/django_downloadview/views/http.py index e8ed199..8b6d329 100644 --- a/django_downloadview/views/http.py +++ b/django_downloadview/views/http.py @@ -1,4 +1,5 @@ """Stream files given an URL, i.e. files you want to proxy.""" + from django_downloadview.files import HTTPFile from django_downloadview.views.base import BaseDownloadView @@ -44,5 +45,5 @@ def get_file(self): request_factory=self.get_request_factory(), name=self.get_basename(), url=self.get_url(), - **self.get_request_kwargs() + **self.get_request_kwargs(), ) diff --git a/django_downloadview/views/object.py b/django_downloadview/views/object.py index 193fa70..3efd628 100644 --- a/django_downloadview/views/object.py +++ b/django_downloadview/views/object.py @@ -1,4 +1,5 @@ """Stream files that live in models.""" + from django.views.generic.detail import SingleObjectMixin from django_downloadview.exceptions import FileNotFound diff --git a/django_downloadview/views/path.py b/django_downloadview/views/path.py index 61327ca..20df49f 100644 --- a/django_downloadview/views/path.py +++ b/django_downloadview/views/path.py @@ -1,4 +1,5 @@ """:class:`PathDownloadView`.""" + import os from django.core.files import File diff --git a/django_downloadview/views/storage.py b/django_downloadview/views/storage.py index 03645d3..376e8e4 100644 --- a/django_downloadview/views/storage.py +++ b/django_downloadview/views/storage.py @@ -1,4 +1,5 @@ """Stream files from storage.""" + from django.core.files.storage import DefaultStorage from django_downloadview.files import StorageFile diff --git a/django_downloadview/views/virtual.py b/django_downloadview/views/virtual.py index 8de0093..7139b5c 100644 --- a/django_downloadview/views/virtual.py +++ b/django_downloadview/views/virtual.py @@ -1,4 +1,5 @@ """Stream files that you generate or that live in memory.""" + from django_downloadview.views.base import BaseDownloadView diff --git a/docs/conf.py b/docs/conf.py index 9e4b80a..5a39a42 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """django-downloadview documentation build configuration file.""" -import os + import re import importlib.metadata @@ -51,7 +51,7 @@ # The full version, including alpha/beta/rc tags. release = importlib.metadata.version("django-downloadview") # The short X.Y version. -version = '.'.join(release.split('.')[:2]) +version = ".".join(release.split(".")[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/files.txt b/docs/files.txt index bd82b30..ecb5392 100644 --- a/docs/files.txt +++ b/docs/files.txt @@ -21,7 +21,7 @@ Django's builtins wrapper in :doc:`/views/path`. * :class:`django.db.models.fields.files.FieldFile` wraps a file that is - managed in a model. ``django-downloadview`` uses this wrapper in + managed in a model. ``django-downloadview`` uses this wrapper in :doc:`/views/object`. * :class:`django.core.files.base.ContentFile` wraps a bytes, string or diff --git a/docs/optimizations/nginx.txt b/docs/optimizations/nginx.txt index 856fcd8..573ea4a 100644 --- a/docs/optimizations/nginx.txt +++ b/docs/optimizations/nginx.txt @@ -142,7 +142,7 @@ Here is what you could have in :file:`/etc/nginx/sites-available/default`: internal; # Location to files on disk. alias /var/www/files/; - } + } # Proxy to Django-powered frontend. location / { @@ -154,7 +154,7 @@ Here is what you could have in :file:`/etc/nginx/sites-available/default`: } ... where specific configuration is the ``location /optimized-download`` -section. +section. .. note:: @@ -192,4 +192,4 @@ they should be equal. .. target-notes:: -.. _`Nginx X-accel documentation`: http://wiki.nginx.org/X-accel +.. _`Nginx X-accel documentation`: http://wiki.nginx.org/X-accel diff --git a/docs/overview.txt b/docs/overview.txt index 503b72e..34a92bc 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -61,7 +61,7 @@ possible, file wrappers do not embed file data, in order to save memory. Learn more about available file wrappers in :doc:`files`. - + ***************************************************************** Middlewares convert DownloadResponse into ProxiedDownloadResponse ***************************************************************** diff --git a/docs/testing.txt b/docs/testing.txt index 5be8a2b..dceaeed 100644 --- a/docs/testing.txt +++ b/docs/testing.txt @@ -41,4 +41,3 @@ Example, related to :doc:`StorageDownloadView demo `: .. literalinclude:: /../demo/demoproject/storage/tests.py :language: python :lines: 1-2, 8-12, 59- - diff --git a/setup.py b/setup.py index aeb4fd6..7526d6c 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup_requires=["setuptools_scm"], description="Serve files with Django and reverse-proxies.", long_description=open(os.path.join(here, "README.rst")).read(), - long_description_content_type='text/x-rst', + long_description_content_type="text/x-rst", classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: BSD License", @@ -20,9 +20,9 @@ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - 'Framework :: Django', - 'Framework :: Django :: 4.2', - 'Framework :: Django :: 5.0', + "Framework :: Django", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", ], keywords=" ".join( [ diff --git a/tests/api.py b/tests/api.py index f1a6890..2377a63 100644 --- a/tests/api.py +++ b/tests/api.py @@ -1,4 +1,5 @@ """Test suite around :mod:`django_downloadview.api` and deprecation plan.""" + from importlib import import_module, reload import unittest import warnings diff --git a/tests/io.py b/tests/io.py index ec3b147..442800c 100644 --- a/tests/io.py +++ b/tests/io.py @@ -1,4 +1,5 @@ """Tests around :mod:`django_downloadview.io`.""" + import unittest from django_downloadview import BytesIteratorIO, TextIteratorIO diff --git a/tests/packaging.py b/tests/packaging.py index ce2b705..deea961 100644 --- a/tests/packaging.py +++ b/tests/packaging.py @@ -1,4 +1,5 @@ """Tests around project's distribution and packaging.""" + import importlib.metadata import os import unittest diff --git a/tests/response.py b/tests/response.py index 738d364..822511e 100644 --- a/tests/response.py +++ b/tests/response.py @@ -1,4 +1,5 @@ """Unit tests around responses.""" + import unittest from django_downloadview.response import DownloadResponse @@ -23,12 +24,9 @@ def test_content_disposition_encoding(self): def test_content_disposition_escaping(self): """Content-Disposition headers escape special characters.""" response = DownloadResponse( - "fake file", - attachment=True, - basename=r'"malicious\file.exe' + "fake file", attachment=True, basename=r'"malicious\file.exe' ) headers = response.default_headers self.assertIn( - r'filename="\"malicious\\file.exe"', - headers["Content-Disposition"] - ) \ No newline at end of file + r'filename="\"malicious\\file.exe"', headers["Content-Disposition"] + ) diff --git a/tests/sendfile.py b/tests/sendfile.py index 21ee719..ce93f69 100644 --- a/tests/sendfile.py +++ b/tests/sendfile.py @@ -1,4 +1,5 @@ """Tests around :py:mod:`django_downloadview.sendfile`.""" + from django.http import Http404 import django.test diff --git a/tests/views.py b/tests/views.py index e9bfa91..78afc72 100644 --- a/tests/views.py +++ b/tests/views.py @@ -1,4 +1,5 @@ """Tests around :mod:`django_downloadview.views`.""" + import calendar from datetime import datetime import os