From 277ff7ef674c6ea85041bba84cafa5b1e2347091 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 6 Oct 2018 04:56:39 -0400 Subject: [PATCH] Update compressed files class module to work with Python 3. Signed-off-by: Roberto Rosario --- mayan/apps/common/compressed_files.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mayan/apps/common/compressed_files.py b/mayan/apps/common/compressed_files.py index ff21f8984e..650aa1e527 100644 --- a/mayan/apps/common/compressed_files.py +++ b/mayan/apps/common/compressed_files.py @@ -114,9 +114,18 @@ class ZipArchive(Archive): self._archive = zipfile.ZipFile(file_object) def add_file(self, file_object, filename): + # Remove the zinfo_or_arcname and bytes keyword arguments + # so that the writestr methods works on Python 2 and 3 + # Python 2 syntax: + # ZipFile.writestr(zinfo_or_arcname, bytes[, compress_type]) + # Python 3 syntax: + # ZipFile.writestr( + # zinfo_or_arcname, data, compress_type=None, compresslevel=None + # ) + # TODO: Change this to keyword arguments when the move to Python 3 + # and Django 2.x is complete. self._archive.writestr( - zinfo_or_arcname=filename, bytes=file_object.read(), - compress_type=COMPRESSION + filename, file_object.read(), compress_type=COMPRESSION ) def create(self):