Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #8149 -- Use universal line terminators when iterating File obje... #320

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions django/core/files/base.py
Expand Up @@ -91,9 +91,7 @@ def __iter__(self):
# Iterate over this file-like object by newlines
buffer_ = None
for chunk in self.chunks():
chunk_buffer = BytesIO(chunk)

for line in chunk_buffer:
for line in chunk.splitlines(True):
if buffer_:
line = buffer_ + line
buffer_ = None
Expand Down
9 changes: 5 additions & 4 deletions docs/topics/http/file-uploads.txt
Expand Up @@ -256,10 +256,11 @@ define the following methods/attributes:
for line in uploadedfile:
do_something_with(line)

However, *unlike* standard Python files, :class:`UploadedFile` only
understands ``\n`` (also known as "Unix-style") line endings. If you know
that you need to handle uploaded files with different line endings, you'll
need to do so in your view.
.. versionchanged:: 1.5

In previous versions, :class:`UploadedFile` only understood ``\n`` (also
known as "Unix-style") line endings. Now, you can read files line-by-line
when they use ``\r`` line endings as well.

Upload Handlers
===============
Expand Down