In #8149 [1] I reported that `UploadedFile` uses `StringIO` to iterate
through uploaded files line-by-line, but `StringIO` only treats `\n`
as a line ending, at least in the current version.

This effectively means we can't use line-by-line iteration over
uploaded files because we don't know what format users (who could be
using Windows, Linux, Mac, etc) will upload files. The problem is
further compounded by the fact that uploaded files may or may not
exist entirely in memory in a temporary file on the file system,
depending on the file size, which makes a work-around a little more
complicated.

The alternatives that I see for developers using django and needing to
iterate through uploaded files are:

1) Save a real file on the file system, open it and then iterate
through it.
2) Load the entire (non-chunked) content of the uploaded file into
memory and use `splitlines`.
3) Monkey patch `File` and re-write `__iter__` in a way that supports
other line ending formats.

#1 and #2 seem to negate the benefits that come with using
`File.__iter__`.

The ticket was marked wontfix, but the explanation doesn't quite make
sense to me. The discussion from django-dev can be found on [2] at
19:50 and 21:31, where it seems that the biggest objection was a gross
regular expression (and I assume the 1.0 deadline), in which case I
think it should have been marked accepted, with "patch needs
improvement".

Although Malcolm didn't have much time to discuss the issue that day,
he did agree that because we must account for the lowest common
denominator and it's *possible* to upload files with `\r\n` and `\r`
line endings, we probably can't count on use line-by-line iteration
over uploaded files.

Now that everyone is not so busy with 1.0, I'd like to re-open this
ticket, or at least gain a better understanding of the reasoning
behind the wontfix, because to me it seems like the opposite is true.
The reason we should support this is because we can't know the format
of uploaded files, not the other way around.

Cheers.
Tai.

[1] http://code.djangoproject.com/ticket/8149
[2] http://oebfare.com/logger/django-dev/2008/08/28/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to