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:
parent
3513234cf8
commit
f3ae496201
|
@ -25,16 +25,11 @@ class Storage(object):
|
||||||
# The following methods represent a public interface to private methods.
|
# The following methods represent a public interface to private methods.
|
||||||
# These shouldn't be overridden by subclasses unless absolutely necessary.
|
# 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
|
Retrieves the specified file from storage.
|
||||||
class to customize what features are available on the File returned.
|
|
||||||
"""
|
"""
|
||||||
file = self._open(name, mode)
|
return 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
|
|
||||||
|
|
||||||
def save(self, name, content):
|
def save(self, name, content):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -527,6 +527,30 @@ This functionality has been removed due to intractable performance and
|
||||||
security issues. Any existing usage of ``verify_exists`` should be
|
security issues. Any existing usage of ``verify_exists`` should be
|
||||||
removed.
|
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:
|
.. _deprecated-features-1.4:
|
||||||
|
|
||||||
|
|
|
@ -231,26 +231,6 @@ class FileStorageTests(unittest.TestCase):
|
||||||
self.storage.base_url = None
|
self.storage.base_url = None
|
||||||
self.assertRaises(ValueError, self.storage.url, 'test.file')
|
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):
|
def test_listdir(self):
|
||||||
"""
|
"""
|
||||||
File storage returns a tuple containing directories and files.
|
File storage returns a tuple containing directories and files.
|
||||||
|
|
Loading…
Reference in New Issue