summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-27 20:53:02 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-27 20:53:02 +0000
commitc33aeaa082b2f821db0b87afbd01f5e0144b9aa4 (patch)
tree4a2e7c1bf386f1d22d1d6833945694b612274c7a
parent40e5cde1c55d4e096fb039daef674f1754cacd5c (diff)
FIxed #8156: `UploadedFile.__repr__` now returns a string, a good `__repr__` should.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8636 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/files/uploadedfile.py3
-rw-r--r--tests/regressiontests/file_storage/tests.py9
2 files changed, 11 insertions, 1 deletions
diff --git a/django/core/files/uploadedfile.py b/django/core/files/uploadedfile.py
index b15f8d535f..9fc4bcbbe5 100644
--- a/django/core/files/uploadedfile.py
+++ b/django/core/files/uploadedfile.py
@@ -11,6 +11,7 @@ except ImportError:
from django.conf import settings
from django.core.files.base import File
from django.core.files import temp as tempfile
+from django.utils.encoding import smart_str
__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
'SimpleUploadedFile')
@@ -32,7 +33,7 @@ class UploadedFile(File):
self.charset = charset
def __repr__(self):
- return "<%s: %s (%s)>" % (self.__class__.__name__, self.name, self.content_type)
+ return "<%s: %s (%s)>" % (self.__class__.__name__, smart_str(self.name), self.content_type)
def _get_name(self):
return self._name
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index a2b6baa07b..3f059c7f3c 100644
--- a/tests/regressiontests/file_storage/tests.py
+++ b/tests/regressiontests/file_storage/tests.py
@@ -1,3 +1,4 @@
+# coding: utf-8
"""
Tests for the file storage mechanism
@@ -72,6 +73,14 @@ u'custom_storage.2'
# Cleanup the temp dir
>>> os.rmdir(temp_dir)
+
+# Regression test for #8156: files with unicode names I can't quite figure out the
+# encoding situation between doctest and this file, but the actual repr doesn't
+# matter; it just shouldn't return a unicode object.
+>>> from django.core.files.uploadedfile import UploadedFile
+>>> uf = UploadedFile(name=u'¿Cómo?',content_type='text')
+>>> uf.__repr__()
+'<UploadedFile: ... (text)>'
"""
# Tests for a race condition on file saving (#4948).