summaryrefslogtreecommitdiff
path: root/paste/gzipper.py
diff options
context:
space:
mode:
Diffstat (limited to 'paste/gzipper.py')
-rw-r--r--paste/gzipper.py15
1 files changed, 9 insertions, 6 deletions
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'):