Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@mrmachine

...cts line-by-line.

@claudep
Collaborator

Thanks, but tests are needed.

@claudep claudep closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. Fixed #8149 -- Use universal line terminators when iterating `File` o…

    Tai Lee authored
    …bjects line-by-line.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 7 deletions.
  1. +1 −3 django/core/files/base.py
  2. +5 −4 docs/topics/http/file-uploads.txt
View
4 django/core/files/base.py
@@ -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
View
9 docs/topics/http/file-uploads.txt
@@ -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
===============
Something went wrong with that request. Please try again.