From ea02c5e0732bec53e3c16f705c6e301ff4d09a1d Mon Sep 17 00:00:00 2001 From: benoitc Date: Sun, 28 Feb 2010 22:22:09 +0100 Subject: [PATCH] this seems to fix problem with upload. Tested with the django app --- examples/djangotest/testing/views.py | 1 + gunicorn/http/tee.py | 9 +++++++-- tests/001-test-parser.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/djangotest/testing/views.py b/examples/djangotest/testing/views.py index 51a77b6b..f7ecef16 100755 --- a/examples/djangotest/testing/views.py +++ b/examples/djangotest/testing/views.py @@ -26,6 +26,7 @@ def home(request): tmp = tempfile.TemporaryFile() for chunk in f.chunks(): tmp.write(chunk) + tmp.flush() size = int(os.fstat(tmp.fileno())[6]) else: form = MsgForm() diff --git a/gunicorn/http/tee.py b/gunicorn/http/tee.py index 18434d2a..337ea6ba 100644 --- a/gunicorn/http/tee.py +++ b/gunicorn/http/tee.py @@ -33,7 +33,7 @@ class TeeInput(object): if len(buf) > 0: chunk, self.buf = parser.filter_body(buf) if chunk: - fwrite(self.tmp, chunk) + self.tmp.write(chunk) self._finalize() self.tmp.seek(0) @@ -42,9 +42,12 @@ class TeeInput(object): if self._len: return self._len if self._is_socket: + pos = self.tmp.tell() while True: + self.tmp.seek(self._tmp_size()) if not self._tee(CHUNK_SIZE): break + self.tmp.seek(0) self._len = self._tmp_size() return self._len @@ -133,7 +136,9 @@ class TeeInput(object): chunk, self.buf = self.parser.filter_body(self.buf) if chunk: - fwrite(self.tmp, chunk) + self.tmp.write(chunk) + self.tmp.flush() + self.tmp.seek(0, os.SEEK_END) return chunk if self.parser.body_eof(): diff --git a/tests/001-test-parser.py b/tests/001-test-parser.py index 81b41e9e..bed62696 100644 --- a/tests/001-test-parser.py +++ b/tests/001-test-parser.py @@ -194,7 +194,7 @@ def test_011(buf, p): t.eq(body, "hello world") @t.request("017.http") -def test_017(buf, p): +def test_013(buf, p): headers = [] i = p.filter_headers(headers, buf) t.ne(i, -1)