Refs #9893 -- Removed shims for lack of max_length support in file storage per deprecation timeline.

This commit is contained in:
Tim Graham 2015-08-20 09:43:07 -04:00
parent 6a70cb5397
commit 1bb6ecf6d3
6 changed files with 2 additions and 84 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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``.

View File

@ -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',
)

View File

@ -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'))