From b18bf426955d85d6cb3d046aa8b074dfe56340c1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 16 Dec 2014 23:02:20 +0100 Subject: [UnZip] Password support --- module/plugins/internal/UnZip.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'module') diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 053946dbe..52e279ccf 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -3,12 +3,12 @@ import sys import zipfile -from module.plugins.internal.AbstractExtractor import AbtractExtractor +from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPassword, ArchiveError class UnZip(AbtractExtractor): __name__ = "UnZip" - __version__ = "0.10" + __version__ = "0.11" __description__ = """Zip extractor plugin""" __license__ = "GPLv3" @@ -32,9 +32,19 @@ class UnZip(AbtractExtractor): def extract(self, progress, password=None): - z = zipfile.ZipFile(self.file) - self.files = z.namelist() - z.extractall(self.out) + try: + z = zipfile.ZipFile(self.file) + self.files = z.namelist() + z.extractall(self.out, pwd=password) + + except (BadZipfile, LargeZipFile), e: + raise ArchiveError(e) + + except RuntimeError, e: + if e is "Bad password for file": + raise WrongPassword + else: + raise ArchiveError(e) def getDeleteFiles(self): -- cgit v1.2.3