Fix AttributeError: ZipFile instance has no attribute '__exit__' in Python 2.6.x

This commit is contained in:
Christopher Ramírez 2014-07-19 19:52:40 -06:00
parent f54ba5fdba
commit fe28417809

View file

@ -125,7 +125,7 @@ class Renderer(object):
self.log.debug('Unpacking template file')
archive_files = {}
with zipfile.ZipFile(template, 'r') as archive:
archive = zipfile.ZipFile(template, 'r')
for zfile in archive.filelist:
archive_files[zfile.filename] = archive.read(zfile.filename)
@ -139,7 +139,7 @@ class Renderer(object):
self.log.debug('packing document')
zip_file = io.BytesIO()
with zipfile.ZipFile(zip_file, 'a') as zipdoc:
zipdoc = zipfile.ZipFile(zip_file, 'a')
for fname, content in files.items():
if sys.version_info >= (2, 7):
zipdoc.writestr(fname, content, zipfile.ZIP_DEFLATED)