mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-03-16 22:40:25 +00:00
Use python3 super and remove useless method re-definitions
This commit is contained in:
parent
338e17195f
commit
ff5073d00b
12 changed files with 18 additions and 42 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ class XSendfileMiddleware(ProxiedDownloadMiddleware):
|
|||
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."""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ class VirtualFile(File):
|
|||
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 @@ class VirtualFile(File):
|
|||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class RealDownloadMiddleware(BaseDownloadMiddleware):
|
|||
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 @@ class SmartDownloadMiddleware(DownloadDispatcherMiddleware):
|
|||
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 @@ class ProxiedDownloadMiddleware(RealDownloadMiddleware):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ class XAccelRedirectMiddleware(ProxiedDownloadMiddleware):
|
|||
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 @@ class SingleXAccelRedirectMiddleware(XAccelRedirectMiddleware):
|
|||
"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,
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class DownloadResponse(StreamingHttpResponse):
|
|||
#: A :doc:`file wrapper instance </files>`, 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 @@ class DownloadResponse(StreamingHttpResponse):
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ class temporary_media_root(override_settings):
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class ObjectDownloadView(SingleObjectMixin, BaseDownloadView):
|
|||
|
||||
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 @@ class ObjectDownloadView(SingleObjectMixin, BaseDownloadView):
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in a new issue