From ff5073d00b1fb6a831df1c1d6a929c7fae1aae84 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 26 Sep 2023 11:24:32 +0200 Subject: [PATCH] Use python3 super and remove useless method re-definitions --- demo/demoproject/path/views.py | 2 +- demo/demoproject/storage/views.py | 2 +- django_downloadview/apache/middlewares.py | 4 +--- django_downloadview/apache/response.py | 2 +- django_downloadview/files.py | 4 ++-- django_downloadview/middlewares.py | 8 ++++---- django_downloadview/nginx/middlewares.py | 6 ++---- django_downloadview/response.py | 12 +----------- django_downloadview/storage.py | 2 +- django_downloadview/test.py | 4 ++-- django_downloadview/views/object.py | 4 ++-- django_downloadview/views/storage.py | 10 ---------- 12 files changed, 18 insertions(+), 42 deletions(-) diff --git a/demo/demoproject/path/views.py b/demo/demoproject/path/views.py index 2af02e3..f1e863d 100644 --- a/demo/demoproject/path/views.py +++ b/demo/demoproject/path/views.py @@ -30,7 +30,7 @@ class DynamicPathDownloadView(PathDownloadView): def get_path(self): """Return path inside fixtures directory.""" # Get path from URL resolvers or as_view kwarg. - relative_path = super(DynamicPathDownloadView, self).get_path() + relative_path = super().get_path() # Make it absolute. absolute_path = os.path.join(fixtures_dir, relative_path) return absolute_path diff --git a/demo/demoproject/storage/views.py b/demo/demoproject/storage/views.py index 91db3f5..1218bc8 100644 --- a/demo/demoproject/storage/views.py +++ b/demo/demoproject/storage/views.py @@ -14,7 +14,7 @@ class DynamicStorageDownloadView(StorageDownloadView): def get_path(self): """Return uppercase path.""" - return super(DynamicStorageDownloadView, self).get_path().upper() + return super().get_path().upper() dynamic_path = DynamicStorageDownloadView.as_view(storage=storage) diff --git a/django_downloadview/apache/middlewares.py b/django_downloadview/apache/middlewares.py index f30cc42..cada074 100644 --- a/django_downloadview/apache/middlewares.py +++ b/django_downloadview/apache/middlewares.py @@ -19,9 +19,7 @@ def __init__( self, get_response=None, source_dir=None, source_url=None, destination_dir=None ): """Constructor.""" - super(XSendfileMiddleware, self).__init__( - get_response, source_dir, source_url, destination_dir - ) + super().__init__(get_response, source_dir, source_url, destination_dir) def process_download_response(self, request, response): """Replace DownloadResponse instances by XSendfileResponse ones.""" diff --git a/django_downloadview/apache/response.py b/django_downloadview/apache/response.py index 5f02aed..b4ad826 100644 --- a/django_downloadview/apache/response.py +++ b/django_downloadview/apache/response.py @@ -9,7 +9,7 @@ class XSendfileResponse(ProxiedDownloadResponse): def __init__(self, file_path, content_type, basename=None, attachment=True): """Return a HttpResponse with headers for Apache X-Sendfile.""" - super(XSendfileResponse, self).__init__(content_type=content_type) + super().__init__(content_type=content_type) if attachment: self.basename = basename or os.path.basename(file_path) self["Content-Disposition"] = content_disposition(self.basename) diff --git a/django_downloadview/files.py b/django_downloadview/files.py index 96fdceb..5341bbe 100644 --- a/django_downloadview/files.py +++ b/django_downloadview/files.py @@ -167,7 +167,7 @@ def __init__(self, file=None, name="", url="", size=None): File URL. """ - super(VirtualFile, self).__init__(file, name) + super().__init__(file, name) self.url = url if size is not None: self._size = size @@ -183,7 +183,7 @@ def _get_size(self): return self._size def _set_size(self, value): - return super(VirtualFile, self)._set_size(value) + return super()._set_size(value) size = property(_get_size, _set_size) diff --git a/django_downloadview/middlewares.py b/django_downloadview/middlewares.py index 782917b..e24b083 100644 --- a/django_downloadview/middlewares.py +++ b/django_downloadview/middlewares.py @@ -75,7 +75,7 @@ def is_download_response(self, response): whose file attribute have either an URL or a file name. """ - if super(RealDownloadMiddleware, self).is_download_response(response): + if super().is_download_response(response): try: return response.file.url or response.file.name except AttributeError: @@ -113,7 +113,7 @@ class DownloadDispatcherMiddleware(BaseDownloadMiddleware): "Download middleware that dispatches job to several middleware instances." def __init__(self, get_response, middlewares=AUTO_CONFIGURE): - super(DownloadDispatcherMiddleware, self).__init__(get_response) + super().__init__(get_response) self.dispatcher = DownloadDispatcher(middlewares) def process_download_response(self, request, response): @@ -130,7 +130,7 @@ def __init__( backend_options=AUTO_CONFIGURE, ): """Constructor.""" - super(SmartDownloadMiddleware, self).__init__(get_response, middlewares=[]) + super().__init__(get_response, middlewares=[]) #: Callable (typically a class) to instantiate backend (typically a #: :class:`DownloadMiddleware` subclass). self.backend_factory = backend_factory @@ -187,7 +187,7 @@ def __init__( self, get_response, source_dir=None, source_url=None, destination_url=None ): """Constructor.""" - super(ProxiedDownloadMiddleware, self).__init__(get_response) + super().__init__(get_response) self.source_dir = source_dir self.source_url = source_url diff --git a/django_downloadview/nginx/middlewares.py b/django_downloadview/nginx/middlewares.py index 3592937..cf70750 100644 --- a/django_downloadview/nginx/middlewares.py +++ b/django_downloadview/nginx/middlewares.py @@ -58,9 +58,7 @@ def __init__( else: source_dir = source_dir - super(XAccelRedirectMiddleware, self).__init__( - get_response, source_dir, source_url, destination_url - ) + super().__init__(get_response, source_dir, source_url, destination_url) self.expires = expires self.with_buffering = with_buffering @@ -132,7 +130,7 @@ def __init__(self, get_response=None): "settings.NGINX_DOWNLOAD_MIDDLEWARE_DESTINATION_URL is " "required by %s middleware" % self.__class__.__name__ ) - super(SingleXAccelRedirectMiddleware, self).__init__( + super().__init__( get_response=get_response, source_dir=settings.NGINX_DOWNLOAD_MIDDLEWARE_SOURCE_DIR, source_url=settings.NGINX_DOWNLOAD_MIDDLEWARE_SOURCE_URL, diff --git a/django_downloadview/response.py b/django_downloadview/response.py index 3f390b6..3c9ae9d 100644 --- a/django_downloadview/response.py +++ b/django_downloadview/response.py @@ -138,7 +138,7 @@ def __init__( #: A :doc:`file wrapper instance `, such as #: :class:`~django.core.files.base.File`. self.file = file_instance - super(DownloadResponse, self).__init__( + super().__init__( streaming_content=self.file, status=status, content_type=content_type ) @@ -195,16 +195,6 @@ def default_headers(self): self._default_headers = headers return self._default_headers - def items(self): - """Return iterable of (header, value). - - This method is called by http handlers just before WSGI's - start_response() is called... but it is not called by - django.test.ClientHandler! :'( - - """ - return super(DownloadResponse, self).items() - def get_basename(self): """Return basename.""" if self.basename: diff --git a/django_downloadview/storage.py b/django_downloadview/storage.py index 691411d..aef8d9e 100644 --- a/django_downloadview/storage.py +++ b/django_downloadview/storage.py @@ -10,7 +10,7 @@ class SignedURLMixin: """ def url(self, name): - path = super(SignedURLMixin, self).url(name) + path = super().url(name) signer = TimestampSigner() signature = signer.sign(path) return "{}?X-Signature={}".format(path, signature) diff --git a/django_downloadview/test.py b/django_downloadview/test.py index e94b479..d7c06fb 100644 --- a/django_downloadview/test.py +++ b/django_downloadview/test.py @@ -71,13 +71,13 @@ def enable(self): settings.MEDIA_ROOT.""" tmp_dir = tempfile.mkdtemp() self.options["MEDIA_ROOT"] = tmp_dir - super(temporary_media_root, self).enable() + super().enable() def disable(self): """Remove directory settings.MEDIA_ROOT then restore original setting.""" shutil.rmtree(settings.MEDIA_ROOT) - super(temporary_media_root, self).disable() + super().disable() class DownloadResponseValidator(object): diff --git a/django_downloadview/views/object.py b/django_downloadview/views/object.py index 1477493..193fa70 100644 --- a/django_downloadview/views/object.py +++ b/django_downloadview/views/object.py @@ -83,7 +83,7 @@ def get_file(self): def get_basename(self): """Return client-side filename.""" - basename = super(ObjectDownloadView, self).get_basename() + basename = super().get_basename() if basename is None: field = "basename" model_field = getattr(self, "%s_field" % field, False) @@ -93,4 +93,4 @@ def get_basename(self): def get(self, request, *args, **kwargs): self.object = self.get_object() - return super(ObjectDownloadView, self).get(request, *args, **kwargs) + return super().get(request, *args, **kwargs) diff --git a/django_downloadview/views/storage.py b/django_downloadview/views/storage.py index e87b1bd..03645d3 100644 --- a/django_downloadview/views/storage.py +++ b/django_downloadview/views/storage.py @@ -14,16 +14,6 @@ class StorageDownloadView(PathDownloadView): #: Path to the file to serve relative to storage. path = None # Override docstring. - def get_path(self): - """Return path of the file to serve, relative to storage. - - Default implementation simply returns view's :py:attr:`path` attribute. - - Override this method if you want custom implementation. - - """ - return super(StorageDownloadView, self).get_path() - def get_file(self): """Return :class:`~django_downloadview.files.StorageFile` instance.""" return StorageFile(self.storage, self.get_path())