Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve codebase to python3 #207

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/demoproject/path/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion demo/demoproject/storage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 1 addition & 3 deletions django_downloadview/apache/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion django_downloadview/apache/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions django_downloadview/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
File URL.

"""
super(VirtualFile, self).__init__(file, name)
super().__init__(file, name)
self.url = url
if size is not None:
self._size = size
Expand All @@ -183,7 +183,7 @@
return self._size

def _set_size(self, value):
return super(VirtualFile, self)._set_size(value)
return super()._set_size(value)

Check warning on line 186 in django_downloadview/files.py

View check run for this annotation

Codecov / codecov/patch

django_downloadview/files.py#L186

Added line #L186 was not covered by tests

size = property(_get_size, _set_size)

Expand Down
8 changes: 4 additions & 4 deletions django_downloadview/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions django_downloadview/nginx/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
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
Expand Down Expand Up @@ -132,7 +130,7 @@
"settings.NGINX_DOWNLOAD_MIDDLEWARE_DESTINATION_URL is "
"required by %s middleware" % self.__class__.__name__
)
super(SingleXAccelRedirectMiddleware, self).__init__(
super().__init__(

Check warning on line 133 in django_downloadview/nginx/middlewares.py

View check run for this annotation

Codecov / codecov/patch

django_downloadview/nginx/middlewares.py#L133

Added line #L133 was not covered by tests
get_response=get_response,
source_dir=settings.NGINX_DOWNLOAD_MIDDLEWARE_SOURCE_DIR,
source_url=settings.NGINX_DOWNLOAD_MIDDLEWARE_SOURCE_URL,
Expand Down
12 changes: 1 addition & 11 deletions django_downloadview/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(
#: 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
)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django_downloadview/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

def url(self, name):
path = super(SignedURLMixin, self).url(name)
path = super().url(name)

Check warning on line 13 in django_downloadview/storage.py

View check run for this annotation

Codecov / codecov/patch

django_downloadview/storage.py#L13

Added line #L13 was not covered by tests
signer = TimestampSigner()
signature = signer.sign(path)
return "{}?X-Signature={}".format(path, signature)
Expand Down
4 changes: 2 additions & 2 deletions django_downloadview/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions django_downloadview/views/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
10 changes: 0 additions & 10 deletions django_downloadview/views/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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