#21321: File.__iter__().chunk python3 compatibility
----------------------------------+------------------------------------
Reporter: jeremiahsavage@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: python3 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by benoitbryon):
> In Python 2.7, if "chunk" is unicode, we get the same kind of error.
Here is a simple example to reproduce the story...
With "str" it works fine:
{{{
>>> from StringIO import StringIO
>>> from django.core.files import File
>>> str_file = StringIO('Hello world')
>>> str_file_wrapper = File(str_file)
>>> [chunk for chunk in str_file_wrapper]
['Hello world']
}}}
But with unicode ValueError is raised:
{{{
>>> unicode_file = StringIO(u'Hello world')
>>> unicode_file_wrapper = File(unicode_file)
>>> [chunk for chunk in unicode_file_wrapper]
Traceback (most recent call last):
...
File "/mnt/data/web/django-
downloadview/lib/buildout/eggs/Django-1.5-py2.7.egg/django/core/files/base.py",
line 97, in __iter__
chunk_buffer = BytesIO(chunk)
TypeError: 'unicode' does not have the buffer interface
}}}
Is the use case valid? Is File intended to support such file objects?
In django-downloadview, I use something similar to support generators
(files that are generated via "yield" statement). Having "yield u'Hello
world'" is valid, isn't it?
Should I use another file wrapper that inherits File? Something similar to
ContentFile, but for generators?
--
Ticket URL: <https://code.djangoproject.com/ticket/21321#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/082.b984b4aa7aababf0642735cabcd9520f%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.