diff --git a/django/core/files/base.py b/django/core/files/base.py
index 48d0be4..1a5e0d4 100644
a
|
b
|
|
1 | 1 | import os |
2 | 2 | try: |
3 | | from cStringIO import StringIO |
| 3 | from cStringIO import StringIO as fastStringIO |
4 | 4 | except ImportError: |
5 | | from StringIO import StringIO |
| 5 | from StringIO import StringIO as fastStringIO |
| 6 | from StringIO import StringIO |
6 | 7 | |
7 | 8 | from django.utils.encoding import smart_str, smart_unicode |
8 | 9 | from django.core.files.utils import FileProxyMixin |
… |
… |
class File(FileProxyMixin):
|
84 | 85 | # Iterate over this file-like object by newlines |
85 | 86 | buffer_ = None |
86 | 87 | for chunk in self.chunks(): |
87 | | chunk_buffer = StringIO(chunk) |
| 88 | chunk_buffer = fastStringIO(chunk) |
88 | 89 | |
89 | 90 | for line in chunk_buffer: |
90 | 91 | if buffer_: |
… |
… |
class ContentFile(File):
|
124 | 125 | """ |
125 | 126 | def __init__(self, content, name=None): |
126 | 127 | content = content or '' |
127 | | super(ContentFile, self).__init__(StringIO(content), name=name) |
| 128 | if isinstance(content, unicode): |
| 129 | # fastStringIO might be linked to cStringIO, which doesn't support |
| 130 | # unicode content (#11739) |
| 131 | file_wrapper = StringIO(content) |
| 132 | else: |
| 133 | file_wrapper = fastStringIO(content) |
| 134 | super(ContentFile, self).__init__(file_wrapper, name=name) |
128 | 135 | self.size = len(content) |
129 | 136 | |
130 | 137 | def __str__(self): |
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index d1ecbe6..576c1c3 100644
a
|
b
|
class ContentFileTestCase(unittest.TestCase):
|
553 | 553 | def test_content_file_custome_name(self): |
554 | 554 | name = "I can have a name too!" |
555 | 555 | self.assertEqual(ContentFile("content", name=name).name, name) |
| 556 | |
| 557 | class ContentFileUnicodeBug(unittest.TestCase): |
| 558 | """ |
| 559 | Tests that ContentFile instances can contain unicode (#11739) |
| 560 | """ |
| 561 | def test_unicode(self): |
| 562 | """ |
| 563 | ContentFile instances should be able to handle unicode. |
| 564 | """ |
| 565 | snowman = u'☃' |
| 566 | file = ContentFile(snowman) |
| 567 | self.assertEqual(file.read(), snowman) |