From f6ef23ba610ffe47d08d9684ba6bd554c78862fb Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Mon, 7 Mar 2016 15:19:32 -0800 Subject: Make gzip work with app that is generator ``` $ tox ... py26: commands succeeded py27: commands succeeded py34: commands succeeded py35: commands succeeded pypy: commands succeeded congratulations :) ``` --- paste/gzipper.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'paste/gzipper.py') diff --git a/paste/gzipper.py b/paste/gzipper.py index eca8775..5f59141 100644 --- a/paste/gzipper.py +++ b/paste/gzipper.py @@ -71,15 +71,18 @@ class GzipResponse(object): return [s] def finish_response(self, app_iter): - if self.compressible: - output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, - fileobj=self.buffer) - else: - output = self.buffer + output = None + try: for s in app_iter: + if not output: + if self.compressible: + output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, + fileobj=self.buffer) + else: + output = self.buffer output.write(s) - if self.compressible: + if output and self.compressible: output.close() finally: if hasattr(app_iter, 'close'): -- cgit v1.2.1