diff --git a/django/core/files/storage.py b/django/core/files/storage.py index 7590171259..73126a3cb9 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -25,16 +25,11 @@ class Storage(object): # The following methods represent a public interface to private methods. # These shouldn't be overridden by subclasses unless absolutely necessary. - def open(self, name, mode='rb', mixin=None): + def open(self, name, mode='rb'): """ - Retrieves the specified file from storage, using the optional mixin - class to customize what features are available on the File returned. + Retrieves the specified file from storage. """ - file = self._open(name, mode) - if mixin: - # Add the mixin as a parent class of the File returned from storage. - file.__class__ = type(mixin.__name__, (mixin, file.__class__), {}) - return file + return self._open(name, mode) def save(self, name, content): """ diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt index 94c1721992..90c5e24e9d 100644 --- a/docs/releases/1.4.txt +++ b/docs/releases/1.4.txt @@ -527,6 +527,30 @@ This functionality has been removed due to intractable performance and security issues. Any existing usage of ``verify_exists`` should be removed. +``django.core.files.storage.Storage.open`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``open`` method of the base Storage class took an obscure parameter +``mixin`` which allowed to dynamically change the base classes of the +returned file object. In the rare case you relied on the `mixin` parameter, +you can easily achieve the same by overriding the `open` method, e.g.:: + + from django.core.files import File + from django.core.files.storage import FileSystemStorage + + class Spam(File): + """ + Spam, spam, spam, spam and spam. + """ + def ham(self): + return 'eggs' + + class SpamStorage(FileSystemStorage): + """ + A custom file storage backend. + """ + def open(self, name, mode='rb'): + return Spam(open(self.path(name), mode)) .. _deprecated-features-1.4: diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index c50ad91e2f..f00d502931 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -231,26 +231,6 @@ class FileStorageTests(unittest.TestCase): self.storage.base_url = None self.assertRaises(ValueError, self.storage.url, 'test.file') - def test_file_with_mixin(self): - """ - File storage can get a mixin to extend the functionality of the - returned file. - """ - self.assertFalse(self.storage.exists('test.file')) - - class TestFileMixin(object): - mixed_in = True - - f = ContentFile('custom contents') - f_name = self.storage.save('test.file', f) - - self.assertTrue(isinstance( - self.storage.open('test.file', mixin=TestFileMixin), - TestFileMixin - )) - - self.storage.delete('test.file') - def test_listdir(self): """ File storage returns a tuple containing directories and files.