[IMP] ensure file is correctly closed even if file.write() blows up (also -3+2)

bzr revid: xmo@openerp.com-20110915104053-fklc9ae853eytods
This commit is contained in:
Xavier Morel
2011-09-15 12:40:53 +02:00
parent 807955bfdc
commit 7e8b8a3ce8
+2 -3
View File
@@ -440,9 +440,8 @@ class module(osv.osv):
zip_content = urllib.urlopen(mod.url).read()
fname = addons.get_module_path(str(mod.name)+'.zip', downloaded=True)
try:
fp = file(fname, 'wb')
fp.write(zip_content)
fp.close()
with open(fname, 'wb') as fp:
fp.write(zip_content)
except Exception:
self.__logger.exception('Error when trying to create module '
'file %s', fname)