Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
18546b4a
Unverified
Commit
18546b4a
authored
Nov 16, 2021
by
Diederik van der Boor
Browse files
Remove remaining Python 2 code style (py2 support was already dropped)
parent
867777c4
Changes
9
Hide whitespace changes
Inline
Side-by-side
private_storage/fields.py
View file @
18546b4a
#-*- coding: utf-8 -*-
import
datetime
import
logging
import
os
...
...
@@ -41,10 +40,10 @@ class PrivateFileField(models.FileField):
self
.
max_file_size
=
kwargs
.
pop
(
"max_file_size"
,
None
)
kwargs
.
setdefault
(
'storage'
,
private_storage
)
super
(
PrivateFileField
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
clean
(
self
,
*
args
,
**
kwargs
):
data
=
super
(
PrivateFileField
,
self
).
clean
(
*
args
,
**
kwargs
)
data
=
super
().
clean
(
*
args
,
**
kwargs
)
file
=
data
.
file
if
isinstance
(
file
,
UploadedFile
):
# content_type is only available for uploaded files,
...
...
private_storage/models.py
View file @
18546b4a
...
...
@@ -4,7 +4,7 @@ from django.core.files.storage import File, Storage
from
django.utils.functional
import
cached_property
class
PrivateFile
(
object
)
:
class
PrivateFile
:
"""
A wrapper object that describes the file that is being accessed.
"""
...
...
private_storage/servers.py
View file @
18546b4a
...
...
@@ -49,7 +49,7 @@ def add_no_cache_headers(func):
return
_dec
class
DjangoStreamingServer
(
object
)
:
class
DjangoStreamingServer
:
"""
Serve static files through ``wsgi.file_wrapper`` or streaming chunks.
...
...
@@ -60,10 +60,7 @@ class DjangoStreamingServer(object):
@
add_no_cache_headers
def
serve
(
private_file
):
# Support If-Last-Modified
if
sys
.
version_info
>=
(
3
,):
mtime
=
private_file
.
modified_time
.
timestamp
()
else
:
mtime
=
time
.
mktime
(
private_file
.
modified_time
.
timetuple
())
mtime
=
private_file
.
modified_time
.
timestamp
()
size
=
private_file
.
size
if
not
was_modified_since
(
private_file
.
request
.
META
.
get
(
'HTTP_IF_MODIFIED_SINCE'
),
mtime
,
size
):
return
HttpResponseNotModified
()
...
...
@@ -122,7 +119,7 @@ class DjangoServer(DjangoStreamingServer):
return
response
class
ApacheXSendfileServer
(
object
)
:
class
ApacheXSendfileServer
:
"""
Serve files for Apache with ``X-Sendfile``.
"""
...
...
@@ -136,7 +133,7 @@ class ApacheXSendfileServer(object):
return
response
class
NginxXAccelRedirectServer
(
object
)
:
class
NginxXAccelRedirectServer
:
"""
Serve the files for Nginx with ``X-Accel-Redirect``.
Add the following configuration::
...
...
private_storage/storage/files.py
View file @
18546b4a
...
...
@@ -20,7 +20,7 @@ class PrivateFileSystemStorage(FileSystemStorage):
if
location
is
None
:
location
=
appconfig
.
PRIVATE_STORAGE_ROOT
super
(
PrivateFileSystemStorage
,
self
).
__init__
(
super
().
__init__
(
location
=
location
,
base_url
=
base_url
,
**
kwargs
...
...
@@ -34,4 +34,4 @@ class PrivateFileSystemStorage(FileSystemStorage):
def
url
(
self
,
name
):
# Make sure reverse_lazy() is evaluated
self
.
base_url
=
force_str
(
self
.
base_url
)
return
super
(
PrivateFileSystemStorage
,
self
).
url
(
name
)
return
super
().
url
(
name
)
private_storage/storage/s3boto3.py
View file @
18546b4a
...
...
@@ -61,7 +61,7 @@ class PrivateS3BotoStorage(S3Boto3Storage):
return
reverse
(
'serve_private_file'
,
kwargs
=
{
'path'
:
name
})
else
:
# 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
...
...
private_storage/tests/test_views.py
View file @
18546b4a
# encoding: utf-8
from
django.contrib.auth.models
import
User
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.http
import
FileResponse
...
...
@@ -92,9 +91,9 @@ class ViewTests(PrivateFileTestCase):
"""
obj
=
CustomerDossier
.
objects
.
create
(
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..
# This behaves like a standard DetailView
...
...
@@ -116,7 +115,7 @@ class ViewTests(PrivateFileTestCase):
response
=
view
(
request
,
path
=
u
'CustomerDossier/cust2/Heizölrückstoßabdämpfung.txt'
path
=
'CustomerDossier/cust2/Heizölrückstoßabdämpfung.txt'
)
if
method
==
'HEAD'
:
self
.
assertNotIsInstance
(
response
,
FileResponse
)
...
...
private_storage/tests/utils.py
View file @
18546b4a
...
...
@@ -11,7 +11,7 @@ class PrivateFileTestCase(TestCase):
"""
Empty the test folder after each test case.
"""
super
(
PrivateFileTestCase
,
self
).
tearDown
()
super
().
tearDown
()
if
os
.
path
.
exists
(
settings
.
PRIVATE_STORAGE_ROOT
):
shutil
.
rmtree
(
settings
.
PRIVATE_STORAGE_ROOT
)
...
...
private_storage/views.py
View file @
18546b4a
...
...
@@ -126,7 +126,7 @@ class PrivateStorageView(View):
if
'WebKit'
in
user_agent
:
# Support available for UTF-8 encoded strings.
# This also matches Edgee.
return
u
'filename={}'
.
format
(
filename
).
encode
(
"utf-8"
)
return
'filename={}'
.
format
(
filename
).
encode
(
"utf-8"
)
elif
'MSIE'
in
user_agent
:
# IE does not support RFC2231 for internationalized headers, but somehow
# percent-decodes it so this can be used instead. Note that using the word
...
...
@@ -155,7 +155,7 @@ class PrivateStorageDetailView(SingleObjectMixin, PrivateStorageView):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
return
super
(
PrivateStorageDetailView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
return
super
().
get
(
request
,
*
args
,
**
kwargs
)
def
get_path
(
self
):
file
=
getattr
(
self
.
object
,
self
.
model_file_field
)
...
...
setup.cfg
deleted
100644 → 0
View file @
867777c4
[wheel]
# create "py2.py3-none-any.whl" package
universal = 1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment