diff options
Diffstat (limited to 'module/plugins/internal/UnZip.py')
-rw-r--r-- | module/plugins/internal/UnZip.py | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index bace76789..026503be5 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -1,53 +1,52 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. +from __future__ import with_statement - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -""" - -import zipfile +import os import sys +import zipfile -from module.plugins.internal.AbstractExtractor import AbtractExtractor +from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -class UnZip(AbtractExtractor): - __name__ = "UnZip" - __version__ = "0.1" +class UnZip(Extractor): + __name__ = "UnZip" + __version__ = "1.03" __description__ = """Zip extractor plugin""" - __author_name__ = "RaNaN" - __author_mail__ = "RaNaN@pyload.org" + __license__ = "GPLv3" + __authors__ = [("RaNaN", "RaNaN@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] - @staticmethod - def checkDeps(): + EXTENSIONS = [".zip", ".zip64"] + + + @classmethod + def checkDeps(cls): return sys.version_info[:2] >= (2, 6) - @staticmethod - def getTargets(files_ids): - result = [] - for file, id in files_ids: - if file.endswith(".zip"): - result.append((file, id)) + @classmethod + def getTargets(cls, files_ids): + return [(filename, id) for filename, id in files_ids if cls.isArchive(filename)] + - return result + def extract(self, password=None): + try: + with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z: + z.setpassword(self.password) + if not z.testzip(): + z.extractall(self.out) + self.files = z.namelist() + else: + raise CRCError - def extract(self, progress, password=None): - z = zipfile.ZipFile(self.file) - self.files = z.namelist() - z.extractall(self.out) + except (BadZipfile, LargeZipFile), e: + raise ArchiveError(e) - def getDeleteFiles(self): - return [self.file] + except RuntimeError, e: + if "encrypted" in e: + raise PasswordError + else: + raise ArchiveError(e) |