Author: jezdez
Date: 2011-09-13 08:10:49 -0700 (Tue, 13 Sep 2011)
New Revision: 16824
Modified:
django/trunk/django/core/files/storage.py
django/trunk/docs/releases/1.4.txt
django/trunk/tests/regressiontests/file_storage/tests.py
Log:
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.
Modified: django/trunk/django/core/files/storage.py
===================================================================
--- django/trunk/django/core/files/storage.py 2011-09-13 08:22:53 UTC (rev
16823)
+++ django/trunk/django/core/files/storage.py 2011-09-13 15:10:49 UTC (rev
16824)
@@ -25,16 +25,11 @@
# 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):
"""
Modified: django/trunk/docs/releases/1.4.txt
===================================================================
--- django/trunk/docs/releases/1.4.txt 2011-09-13 08:22:53 UTC (rev 16823)
+++ django/trunk/docs/releases/1.4.txt 2011-09-13 15:10:49 UTC (rev 16824)
@@ -527,7 +527,31 @@
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:
Features deprecated in 1.4
Modified: django/trunk/tests/regressiontests/file_storage/tests.py
===================================================================
--- django/trunk/tests/regressiontests/file_storage/tests.py 2011-09-13
08:22:53 UTC (rev 16823)
+++ django/trunk/tests/regressiontests/file_storage/tests.py 2011-09-13
15:10:49 UTC (rev 16824)
@@ -231,26 +231,6 @@
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.