1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #11739 -- Made ContentFile support Unicode input

This commit is contained in:
Claude Paroz
2012-08-29 09:45:02 +02:00
parent ebc773ada3
commit 361d6738f8
3 changed files with 25 additions and 9 deletions

View File

@@ -1,10 +1,11 @@
from __future__ import unicode_literals
import os
from io import BytesIO, UnsupportedOperation
from io import BytesIO, StringIO, UnsupportedOperation
from django.utils.encoding import smart_text
from django.core.files.utils import FileProxyMixin
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
@@ -132,7 +133,8 @@ class ContentFile(File):
"""
def __init__(self, content, name=None):
content = content or b''
super(ContentFile, self).__init__(BytesIO(content), name=name)
stream_class = StringIO if isinstance(content, six.text_type) else BytesIO
super(ContentFile, self).__init__(stream_class(content), name=name)
self.size = len(content)
def __str__(self):