Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16833 -- Removed undocumented `mixin` parameter from the `Stor…

…age.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
  • Loading branch information...
commit f3ae4962017727c16e3e4a35f3d58c232051aa10 1 parent 3513234
@jezdez jezdez authored
View
11 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):
"""
View
24 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:
View
20 tests/regressiontests/file_storage/tests.py
@@ -231,26 +231,6 @@ def test_file_url(self):
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.
Please sign in to comment.
Something went wrong with that request. Please try again.