Fixed a Python 2.6 regression (GzipFile can't act as a context manager)

This commit is contained in:
Łukasz Langa 2013-05-21 13:18:53 +02:00
parent b1ac241ddc
commit c28281f9d6
1 changed files with 4 additions and 1 deletions

View File

@ -11,8 +11,11 @@ from django.test import TestCase
# based on Python 3.3's gzip.compress
def gzip_compress(data):
buf = io.BytesIO()
with gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=0) as f:
f = gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=0)
try:
f.write(data)
finally:
f.close()
return buf.getvalue()