Skip to content

Commit

Permalink
Drop Python 2 support and Django 1.8/1.9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed May 17, 2021
1 parent 4040075 commit e51a3fb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 29 deletions.
10 changes: 1 addition & 9 deletions private_storage/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#-*- coding: utf-8 -*-
from __future__ import unicode_literals

import datetime
import logging
import os
Expand All @@ -23,12 +21,6 @@
logger = logging.getLogger(__name__)


try:
string_types = basestring, # Python 2
except NameError:
string_types = str, # Python 3


class PrivateFileField(models.FileField):
"""
Filefield with private storage, custom filename and size checks.
Expand Down Expand Up @@ -90,7 +82,7 @@ def generate_filename(self, instance, filename):
extra_dirs = upload_subfolder(instance)

# Avoid mistakes by developers, no "s/u/b/p/a/t/h/"
if isinstance(extra_dirs, string_types):
if isinstance(extra_dirs, str):
warnings.warn("{}.{}.upload_subfolder should return a list"
" to avoid path-separator issues.".format(
instance.__class__.__name__, self.name), UserWarning)
Expand Down
12 changes: 2 additions & 10 deletions private_storage/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import os
import sys
import time
from functools import wraps
from functools import lru_cache, wraps
from urllib.parse import quote

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand All @@ -13,15 +14,6 @@
from django.utils.module_loading import import_string
from django.views.static import serve, was_modified_since

try:
# python 3
from urllib.parse import quote
from functools import lru_cache # Python 3
except ImportError:
# python 2
from urllib import quote
from django.utils.lru_cache import lru_cache # Django <3


@lru_cache()
def get_server_class(path):
Expand Down
6 changes: 1 addition & 5 deletions private_storage/storage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
Django Storage interface, using the file system backend.
"""
from django.core.files.storage import FileSystemStorage
from django.urls import reverse_lazy
from django.utils.deconstruct import deconstructible
from django.utils.encoding import force_text

from private_storage import appconfig

try:
from django.urls import reverse_lazy # Added in Django 1.10
except ImportError:
from django.core.urlresolvers import reverse_lazy


@deconstructible
class PrivateFileSystemStorage(FileSystemStorage):
Expand Down
6 changes: 1 addition & 5 deletions private_storage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Views to send private files.
"""
import os
from urllib.parse import quote

from django.http import Http404
from django.utils.module_loading import import_string
Expand All @@ -14,11 +15,6 @@
from .servers import get_server_class
from .storage import private_storage

try:
from urllib.parse import quote
except ImportError:
from urllib import quote # Python 2


class PrivateStorageView(View):
"""
Expand Down
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
},
],
DEFAULT_AUTO_FIELD='django.db.models.BigAutoField',
AWS_PRIVATE_STORAGE_BUCKET_NAME='foobar',
PRIVATE_STORAGE_ROOT=path.join(module_root, 'test-media-root'),
)
Expand Down

0 comments on commit e51a3fb

Please sign in to comment.