Fixed #16833 -- Removed undocumented `mixin` parameter from the `Storage.open()` method as this was an undocumented and obscure feature. Thanks to Marty and Russell for sanity-checking.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16824 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-09-13 15:10:49 +00:00
parent 3513234cf8
commit f3ae496201
3 changed files with 27 additions and 28 deletions

View File

@ -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):
"""

View File

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

View File

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