From cf7322ca43fc6847e61b45fa88bb0a3412a45e59 Mon Sep 17 00:00:00 2001 From: benoitc Date: Thu, 25 Feb 2010 13:04:41 +0100 Subject: [PATCH] fix readline in tee --- gunicorn/http/tee.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gunicorn/http/tee.py b/gunicorn/http/tee.py index 14dcffda..af2cdcdb 100644 --- a/gunicorn/http/tee.py +++ b/gunicorn/http/tee.py @@ -34,8 +34,8 @@ class TeeInput(object): chunk, self.buf = parser.filter_body(buf) if chunk: self.tmp.write(chunk) - self.tmp.seek(0) self._finalize() + self.tmp.seek(0) @property def len(self): @@ -93,12 +93,18 @@ class TeeInput(object): # now we can get line line = self.tmp.readline() - if size > 0 and len(line) < size: - self.tmp.seek(orig_size) + i = line.find("\n") + if i == -1: while True: + orig_size = self.tmp.tell() if not self._tee(CHUNK_SIZE): - self.tmp.seek(orig_size) - return self.temp.readline(size) + break + self.tmp.seek(orig_size) + line = self.tmp.readline() + i = line.find("\n") + if i != -1: + break + return line def readlines(self, sizehint=0): @@ -132,7 +138,8 @@ class TeeInput(object): self.tmp.seek(0, os.SEEK_END) return chunk - if self.parser.body_eof(): break + if self.parser.body_eof(): + break data = read_partial(self.socket, length) self.buf += data