mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'develop' of https://github.com/gazpachoking/requests into develop
This commit is contained in:
+13
-22
@@ -9,7 +9,6 @@ This module contains the primary objects that power Requests.
|
||||
|
||||
import os
|
||||
import urllib
|
||||
import zlib
|
||||
|
||||
from urlparse import urlparse, urlunparse, urljoin, urlsplit
|
||||
from datetime import datetime
|
||||
@@ -630,33 +629,25 @@ class Response(object):
|
||||
return gen
|
||||
|
||||
|
||||
def iter_lines(self, newlines=None, decode_unicode=None):
|
||||
def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None):
|
||||
"""Iterates over the response data, one line at a time. This
|
||||
avoids reading the content at once into memory for large
|
||||
responses.
|
||||
|
||||
:param newlines: a collection of bytes to seperate lines with.
|
||||
"""
|
||||
|
||||
if newlines is None:
|
||||
newlines = ('\r', '\n', '\r\n')
|
||||
pending = None
|
||||
for chunk in self.iter_content(chunk_size, decode_unicode=decode_unicode):
|
||||
if pending is not None:
|
||||
chunk = pending + chunk
|
||||
lines = chunk.splitlines(True)
|
||||
for line in lines[:-1]:
|
||||
yield line.rstrip()
|
||||
# Save the last part of the chunk for next iteration, to keep full line together
|
||||
pending = lines[-1]
|
||||
|
||||
chunk = []
|
||||
|
||||
for c in self.iter_content(1, decode_unicode=decode_unicode):
|
||||
if not c:
|
||||
break
|
||||
|
||||
if c in newlines:
|
||||
yield ''.join(chunk)
|
||||
chunk = []
|
||||
else:
|
||||
chunk.append(c)
|
||||
|
||||
# Yield the remainder, in case the response
|
||||
# did not terminate with a newline
|
||||
if chunk:
|
||||
yield ''.join(chunk)
|
||||
# Yield the last line
|
||||
if pending is not None:
|
||||
yield pending.rstrip()
|
||||
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user