id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux
8156,UnicodeEncodeError on repr of UploadedFile with unicode name,Karen Tracey,marco,"If I create an !UploadedFile with a unicode name that contains non-ASCII chars, I get a !UnicodeEncodeError attempting to display its representation in a Python shell:
{{{
>>> from django.core.files.uploadedfile import UploadedFile
>>> uf = UploadedFile(name=u'¿Cómo',content_type='text')
>>> uf
Traceback (most recent call last):
File """", line 1, in
UnicodeEncodeError: 'ascii' codec can't encode character u'\xbf' in position 15: ordinal not in range(128)
>>> uf.__repr__()
u''
}}}
The implementation of `__repr__` here is:
{{{
def __repr__(self):
return """" % (self.__class__.__name__, self.name, self.content_type)
}}}
I think `__repr__` for !UploadedFile needs to take into account the fact that the file name may be Unicode with non-ASCII chars and convert it into an ASCII-only representation before including it in the return value. As it is this implementation returns unicode, where I thought `__repr__` was supposed to return only a string (per http://docs.python.org/ref/customization.html ""The return value must be a string object."")?",,closed,File uploads/storage,master,,fixed,,,Accepted,1,0,0,0,,