Unverified Commit 18546b4a authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Remove remaining Python 2 code style (py2 support was already dropped)

parent 867777c4
#-*- coding: utf-8 -*-
import datetime import datetime
import logging import logging
import os import os
...@@ -41,10 +40,10 @@ class PrivateFileField(models.FileField): ...@@ -41,10 +40,10 @@ class PrivateFileField(models.FileField):
self.max_file_size = kwargs.pop("max_file_size", None) self.max_file_size = kwargs.pop("max_file_size", None)
kwargs.setdefault('storage', private_storage) kwargs.setdefault('storage', private_storage)
super(PrivateFileField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
data = super(PrivateFileField, self).clean(*args, **kwargs) data = super().clean(*args, **kwargs)
file = data.file file = data.file
if isinstance(file, UploadedFile): if isinstance(file, UploadedFile):
# content_type is only available for uploaded files, # content_type is only available for uploaded files,
......
...@@ -4,7 +4,7 @@ from django.core.files.storage import File, Storage ...@@ -4,7 +4,7 @@ from django.core.files.storage import File, Storage
from django.utils.functional import cached_property from django.utils.functional import cached_property
class PrivateFile(object): class PrivateFile:
""" """
A wrapper object that describes the file that is being accessed. A wrapper object that describes the file that is being accessed.
""" """
......
...@@ -49,7 +49,7 @@ def add_no_cache_headers(func): ...@@ -49,7 +49,7 @@ def add_no_cache_headers(func):
return _dec return _dec
class DjangoStreamingServer(object): class DjangoStreamingServer:
""" """
Serve static files through ``wsgi.file_wrapper`` or streaming chunks. Serve static files through ``wsgi.file_wrapper`` or streaming chunks.
...@@ -60,10 +60,7 @@ class DjangoStreamingServer(object): ...@@ -60,10 +60,7 @@ class DjangoStreamingServer(object):
@add_no_cache_headers @add_no_cache_headers
def serve(private_file): def serve(private_file):
# Support If-Last-Modified # Support If-Last-Modified
if sys.version_info >= (3,): mtime = private_file.modified_time.timestamp()
mtime = private_file.modified_time.timestamp()
else:
mtime = time.mktime(private_file.modified_time.timetuple())
size = private_file.size size = private_file.size
if not was_modified_since(private_file.request.META.get('HTTP_IF_MODIFIED_SINCE'), mtime, size): if not was_modified_since(private_file.request.META.get('HTTP_IF_MODIFIED_SINCE'), mtime, size):
return HttpResponseNotModified() return HttpResponseNotModified()
...@@ -122,7 +119,7 @@ class DjangoServer(DjangoStreamingServer): ...@@ -122,7 +119,7 @@ class DjangoServer(DjangoStreamingServer):
return response return response
class ApacheXSendfileServer(object): class ApacheXSendfileServer:
""" """
Serve files for Apache with ``X-Sendfile``. Serve files for Apache with ``X-Sendfile``.
""" """
...@@ -136,7 +133,7 @@ class ApacheXSendfileServer(object): ...@@ -136,7 +133,7 @@ class ApacheXSendfileServer(object):
return response return response
class NginxXAccelRedirectServer(object): class NginxXAccelRedirectServer:
""" """
Serve the files for Nginx with ``X-Accel-Redirect``. Serve the files for Nginx with ``X-Accel-Redirect``.
Add the following configuration:: Add the following configuration::
......
...@@ -20,7 +20,7 @@ class PrivateFileSystemStorage(FileSystemStorage): ...@@ -20,7 +20,7 @@ class PrivateFileSystemStorage(FileSystemStorage):
if location is None: if location is None:
location = appconfig.PRIVATE_STORAGE_ROOT location = appconfig.PRIVATE_STORAGE_ROOT
super(PrivateFileSystemStorage, self).__init__( super().__init__(
location=location, location=location,
base_url=base_url, base_url=base_url,
**kwargs **kwargs
...@@ -34,4 +34,4 @@ class PrivateFileSystemStorage(FileSystemStorage): ...@@ -34,4 +34,4 @@ class PrivateFileSystemStorage(FileSystemStorage):
def url(self, name): def url(self, name):
# Make sure reverse_lazy() is evaluated # Make sure reverse_lazy() is evaluated
self.base_url = force_str(self.base_url) self.base_url = force_str(self.base_url)
return super(PrivateFileSystemStorage, self).url(name) return super().url(name)
...@@ -61,7 +61,7 @@ class PrivateS3BotoStorage(S3Boto3Storage): ...@@ -61,7 +61,7 @@ class PrivateS3BotoStorage(S3Boto3Storage):
return reverse('serve_private_file', kwargs={'path': name}) return reverse('serve_private_file', kwargs={'path': name})
else: else:
# The S3Boto3Storage can generate a presigned URL that is temporary available. # The S3Boto3Storage can generate a presigned URL that is temporary available.
return super(PrivateS3BotoStorage, self).url(name, *args, **kwargs) return super().url(name, *args, **kwargs)
@deconstructible @deconstructible
......
# encoding: utf-8
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.http import FileResponse from django.http import FileResponse
...@@ -92,9 +91,9 @@ class ViewTests(PrivateFileTestCase): ...@@ -92,9 +91,9 @@ class ViewTests(PrivateFileTestCase):
""" """
obj = CustomerDossier.objects.create( obj = CustomerDossier.objects.create(
customer='cust2', customer='cust2',
file=SimpleUploadedFile(u'Heizölrückstoßabdämpfung.txt', b'test5') file=SimpleUploadedFile('Heizölrückstoßabdämpfung.txt', b'test5')
) )
self.assertExists('CustomerDossier', 'cust2', u'Heizölrückstoßabdämpfung.txt') self.assertExists('CustomerDossier', 'cust2', 'Heizölrückstoßabdämpfung.txt')
# Initialize locally, no need for urls.py etc.. # Initialize locally, no need for urls.py etc..
# This behaves like a standard DetailView # This behaves like a standard DetailView
...@@ -116,7 +115,7 @@ class ViewTests(PrivateFileTestCase): ...@@ -116,7 +115,7 @@ class ViewTests(PrivateFileTestCase):
response = view( response = view(
request, request,
path=u'CustomerDossier/cust2/Heizölrückstoßabdämpfung.txt' path='CustomerDossier/cust2/Heizölrückstoßabdämpfung.txt'
) )
if method == 'HEAD': if method == 'HEAD':
self.assertNotIsInstance(response, FileResponse) self.assertNotIsInstance(response, FileResponse)
......
...@@ -11,7 +11,7 @@ class PrivateFileTestCase(TestCase): ...@@ -11,7 +11,7 @@ class PrivateFileTestCase(TestCase):
""" """
Empty the test folder after each test case. Empty the test folder after each test case.
""" """
super(PrivateFileTestCase, self).tearDown() super().tearDown()
if os.path.exists(settings.PRIVATE_STORAGE_ROOT): if os.path.exists(settings.PRIVATE_STORAGE_ROOT):
shutil.rmtree(settings.PRIVATE_STORAGE_ROOT) shutil.rmtree(settings.PRIVATE_STORAGE_ROOT)
......
...@@ -126,7 +126,7 @@ class PrivateStorageView(View): ...@@ -126,7 +126,7 @@ class PrivateStorageView(View):
if 'WebKit' in user_agent: if 'WebKit' in user_agent:
# Support available for UTF-8 encoded strings. # Support available for UTF-8 encoded strings.
# This also matches Edgee. # This also matches Edgee.
return u'filename={}'.format(filename).encode("utf-8") return 'filename={}'.format(filename).encode("utf-8")
elif 'MSIE' in user_agent: elif 'MSIE' in user_agent:
# IE does not support RFC2231 for internationalized headers, but somehow # IE does not support RFC2231 for internationalized headers, but somehow
# percent-decodes it so this can be used instead. Note that using the word # percent-decodes it so this can be used instead. Note that using the word
...@@ -155,7 +155,7 @@ class PrivateStorageDetailView(SingleObjectMixin, PrivateStorageView): ...@@ -155,7 +155,7 @@ class PrivateStorageDetailView(SingleObjectMixin, PrivateStorageView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
return super(PrivateStorageDetailView, self).get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
def get_path(self): def get_path(self):
file = getattr(self.object, self.model_file_field) file = getattr(self.object, self.model_file_field)
......
[wheel]
# create "py2.py3-none-any.whl" package
universal = 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment