From 5499e558a541a0c8740d608dc4446f64ebe774c6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 26 Mar 2025 17:27:41 +0100 Subject: 🐛 fix unclosed file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/data_importer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ishtar_common/data_importer.py') diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 4259e1b8a..7df66a672 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -647,7 +647,6 @@ class FileFormater(Formater): return my_file def _format_zip(self, value, archive): - zp = zipfile.ZipFile(archive) value = value.strip().replace("\\", "/") items = value.replace("/", "_").split(".") base_dir = settings.MEDIA_ROOT + "imported" @@ -656,14 +655,15 @@ class FileFormater(Formater): filename = base_dir + os.sep + ".".join(items[:-1]) + "." + items[-1] try: - with open(filename, "wb") as f: - with zp.open(value) as z: - f.write(z.read()) - f = open(filename, "rb") - my_file = File(f) - # manually set the file size because of an issue with TempFile - my_file.size = os.stat(filename).st_size - return my_file + with zipfile.ZipFile(archive) as zp: + with open(filename, "wb") as f: + with zp.open(value) as z: + f.write(z.read()) + f = open(filename, "rb") + my_file = File(f) + # manually set the file size because of an issue with TempFile + my_file.size = os.stat(filename).st_size + return my_file except KeyError: raise ValueError( _('"%(value)s" is not a valid path for the given archive') -- cgit v1.2.3