Zipfile is now closed when it's done loading

CURA-2252
This commit is contained in:
Jaime van Kessel 2016-09-08 14:23:35 +02:00
parent 45a841a52b
commit 96a1aafb80

View file

@ -27,15 +27,15 @@ class CuraProfileReader(ProfileReader):
# returned. # returned.
def read(self, file_name): def read(self, file_name):
try: try:
archive = zipfile.ZipFile(file_name, "r") with zipfile.ZipFile(file_name, "r") as archive:
results = [] results = []
for profile_id in archive.namelist(): for profile_id in archive.namelist():
with archive.open(profile_id) as f: with archive.open(profile_id) as f:
serialized = f.read() serialized = f.read()
profile = self._loadProfile(serialized.decode("utf-8"), profile_id) profile = self._loadProfile(serialized.decode("utf-8"), profile_id)
if profile is not None: if profile is not None:
results.append(profile) results.append(profile)
return results return results
except zipfile.BadZipFile: except zipfile.BadZipFile:
# It must be an older profile from Cura 2.1. # It must be an older profile from Cura 2.1.