summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/UnZip.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/UnZip.py')
-rw-r--r--module/plugins/internal/UnZip.py65
1 files changed, 46 insertions, 19 deletions
diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py
index dded6158e..704b49ca0 100644
--- a/module/plugins/internal/UnZip.py
+++ b/module/plugins/internal/UnZip.py
@@ -1,41 +1,68 @@
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
+import os
import sys
import zipfile
-from pyload.plugin.internal.AbstractExtractor import AbtractExtractor
+from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError
+from module.utils import fs_encode
-class UnZip(AbtractExtractor):
+class UnZip(Extractor):
__name__ = "UnZip"
- __version__ = "0.10"
+ __version__ = "1.10"
__description__ = """Zip extractor plugin"""
__license__ = "GPLv3"
- __authors__ = [("RaNaN", "RaNaN@pyload.org")]
+ __authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ EXTENSIONS = [".zip", ".zip64"]
+ VERSION ="(python %s.%s.%s)" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
- @staticmethod
- def checkDeps():
+ @classmethod
+ def isUsable(cls):
return sys.version_info[:2] >= (2, 6)
- @staticmethod
- def getTargets(files_ids):
- result = []
+ def list(self, password=None):
+ with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
+ z.setpassword(password)
+ return z.namelist()
+
+
+ def check(self):
+ with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
+ badfile = z.testzip()
+
+ if badfile:
+ raise CRCError(badfile)
+ else:
+ raise PasswordError
- for file, id in files_ids:
- if file.endswith(".zip"):
- result.append((file, id))
- return result
+ def extract(self, password=None):
+ try:
+ with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
+ z.setpassword(password)
+ badfile = z.testzip()
- def extract(self, progress, password=None):
- z = zipfile.ZipFile(self.file)
- self.files = z.namelist()
- z.extractall(self.out)
+ if badfile:
+ raise CRCError(badfile)
+ else:
+ z.extractall(self.out)
+ except (zipfile.BadZipfile, zipfile.LargeZipFile), e:
+ raise ArchiveError(e)
- def getDeleteFiles(self):
- return [self.file]
+ except RuntimeError, e:
+ if "encrypted" in e:
+ raise PasswordError
+ else:
+ raise ArchiveError(e)
+ else:
+ self.files = z.namelist()