Commit 1bb6ecf6 authored by Tim Graham's avatar Tim Graham
Browse files

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

Refs #9893 -- Removed shims for lack of max_length support in file storage per deprecation timeline.
parent 6a70cb53
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
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._save(name, content)

        # Store filenames with forward slashes, even on Windows
+1 −15
Original line number Diff line number Diff line
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)

        setattr(self.instance, self.field.name, self.name)

        # Update the filesize cache
+0 −4
Original line number Diff line number Diff line
@@ -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.
+0 −8
Original line number Diff line number Diff line
@@ -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``.
+0 −17
Original line number Diff line number Diff line
@@ -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',
    )
Loading