summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-08-20 09:43:07 -0400
committerTim Graham <timograham@gmail.com>2015-09-23 19:31:10 -0400
commit1bb6ecf6d3b31bd606754ddbd1398550f605d3e5 (patch)
tree46d193785b40853a128f6ddefb08d92b3c3b37bd
parent6a70cb53971a19f2d9e71d5ee24bfb0e844b4d9d (diff)
Refs #9893 -- Removed shims for lack of max_length support in file storage per deprecation timeline.
-rw-r--r--django/core/files/storage.py15
-rw-r--r--django/db/models/fields/files.py16
-rw-r--r--docs/howto/custom-file-storage.txt4
-rw-r--r--docs/ref/files/storage.txt8
-rw-r--r--tests/file_storage/models.py17
-rw-r--r--tests/file_storage/tests.py26
6 files changed, 2 insertions, 84 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 39cf5d800b..efd8fc13b7 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -1,6 +1,5 @@
import errno
import os
-import warnings
from datetime import datetime
from django.conf import settings
@@ -10,10 +9,8 @@ from django.core.files.move import file_move_safe
from django.utils._os import abspathu, safe_join
from django.utils.crypto import get_random_string
from django.utils.deconstruct import deconstructible
-from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.encoding import filepath_to_uri, force_text
from django.utils.functional import LazyObject
-from django.utils.inspect import func_supports_parameter
from django.utils.module_loading import import_string
from django.utils.six.moves.urllib.parse import urljoin
from django.utils.text import get_valid_filename
@@ -49,17 +46,7 @@ class Storage(object):
if not hasattr(content, 'chunks'):
content = File(content)
- if func_supports_parameter(self.get_available_name, 'max_length'):
- name = self.get_available_name(name, max_length=max_length)
- else:
- warnings.warn(
- 'Backwards compatibility for storage backends without '
- 'support for the `max_length` argument in '
- 'Storage.get_available_name() will be removed in Django 1.10.',
- RemovedInDjango110Warning, stacklevel=2
- )
- name = self.get_available_name(name)
-
+ name = self.get_available_name(name, max_length=max_length)
name = self._save(name, content)
# Store filenames with forward slashes, even on Windows
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index 760c17b001..184a8dbd69 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -1,6 +1,5 @@
import datetime
import os
-import warnings
from django import forms
from django.core import checks
@@ -10,9 +9,7 @@ from django.core.files.storage import default_storage
from django.db.models import signals
from django.db.models.fields import Field
from django.utils import six
-from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.encoding import force_str, force_text
-from django.utils.inspect import func_supports_parameter
from django.utils.translation import ugettext_lazy as _
@@ -88,18 +85,7 @@ class FieldFile(File):
def save(self, name, content, save=True):
name = self.field.generate_filename(self.instance, name)
-
- if func_supports_parameter(self.storage.save, 'max_length'):
- self.name = self.storage.save(name, content, max_length=self.field.max_length)
- else:
- warnings.warn(
- 'Backwards compatibility for storage backends without '
- 'support for the `max_length` argument in '
- 'Storage.save() will be removed in Django 1.10.',
- RemovedInDjango110Warning, stacklevel=2
- )
- self.name = self.storage.save(name, content)
-
+ self.name = self.storage.save(name, content, max_length=self.field.max_length)
setattr(self.instance, self.field.name, self.name)
# Update the filesize cache
diff --git a/docs/howto/custom-file-storage.txt b/docs/howto/custom-file-storage.txt
index 5140911591..9683dcd20a 100644
--- a/docs/howto/custom-file-storage.txt
+++ b/docs/howto/custom-file-storage.txt
@@ -114,7 +114,3 @@ free unique filename cannot be found, a :exc:`SuspiciousFileOperation
If a file with ``name`` already exists, an underscore plus a random 7 character
alphanumeric string is appended to the filename before the extension.
-
-.. versionchanged:: 1.8
-
- The ``max_length`` argument was added.
diff --git a/docs/ref/files/storage.txt b/docs/ref/files/storage.txt
index 8dd700484d..be9c554341 100644
--- a/docs/ref/files/storage.txt
+++ b/docs/ref/files/storage.txt
@@ -118,10 +118,6 @@ The Storage Class
7 character alphanumeric string is appended to the filename before
the extension.
- .. versionchanged:: 1.8
-
- The ``max_length`` argument was added.
-
.. method:: get_valid_name(name)
Returns a filename based on the ``name`` parameter that's suitable
@@ -168,10 +164,6 @@ The Storage Class
:class:`django.core.files.File` or of a subclass of
:class:`~django.core.files.File`.
- .. versionchanged:: 1.8
-
- The ``max_length`` argument was added.
-
.. method:: size(name)
Returns the total size, in bytes, of the file referenced by ``name``.
diff --git a/tests/file_storage/models.py b/tests/file_storage/models.py
index 9ab8dfbfe2..38675a6673 100644
--- a/tests/file_storage/models.py
+++ b/tests/file_storage/models.py
@@ -12,19 +12,6 @@ from django.core.files.storage import FileSystemStorage
from django.db import models
-class OldStyleFSStorage(FileSystemStorage):
- """
- Storage backend without support for the ``max_length`` argument in
- ``get_available_name()`` and ``save()``; for backward-compatibility and
- deprecation testing.
- """
- def get_available_name(self, name):
- return name
-
- def save(self, name, content):
- return super(OldStyleFSStorage, self).save(name, content)
-
-
class CustomValidNameStorage(FileSystemStorage):
def get_valid_name(self, name):
# mark the name to show that this was called
@@ -55,7 +42,3 @@ class Storage(models.Model):
empty = models.FileField(storage=temp_storage)
limited_length = models.FileField(storage=temp_storage, upload_to='tests', max_length=20)
extended_length = models.FileField(storage=temp_storage, upload_to='tests', max_length=300)
- old_style = models.FileField(
- storage=OldStyleFSStorage(location=temp_storage_location),
- upload_to='tests',
- )
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 9aea27420d..8ff3959427 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -9,7 +9,6 @@ import tempfile
import threading
import time
import unittest
-import warnings
from datetime import datetime, timedelta
from django.core.cache import cache
@@ -555,31 +554,6 @@ class FileFieldStorageTests(TestCase):
self.assertEqual(obj.extended_length.read(), b'Same Content')
obj.extended_length.close()
- def test_old_style_storage(self):
- # Testing backward-compatibility with old-style storage backends that
- # don't take ``max_length`` parameter in ``get_available_name()``
- # and save(). A deprecation warning should be raised.
- obj = Storage()
- with warnings.catch_warnings(record=True) as warns:
- warnings.simplefilter('always')
- obj.old_style.save('deprecated_storage_test.txt', ContentFile('Same Content'))
- self.assertEqual(len(warns), 2)
- self.assertEqual(
- str(warns[0].message),
- 'Backwards compatibility for storage backends without support for '
- 'the `max_length` argument in Storage.save() will be removed in '
- 'Django 1.10.'
- )
- self.assertEqual(
- str(warns[1].message),
- 'Backwards compatibility for storage backends without support for '
- 'the `max_length` argument in Storage.get_available_name() will '
- 'be removed in Django 1.10.'
- )
- self.assertEqual(obj.old_style.name, 'tests/deprecated_storage_test.txt')
- self.assertEqual(obj.old_style.read(), b'Same Content')
- obj.old_style.close()
-
def test_filefield_default(self):
# Default values allow an object to access a single file.
temp_storage.save('tests/default.txt', ContentFile('default content'))