summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/UnZip.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-14 02:51:07 +0100
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-27 20:50:38 +0100
commitd8096353ba12d9e507c1e574f79b9fbff2a1df02 (patch)
tree8caab2980ad607dd147d8267974ae3fde2ec4be1 /module/plugins/internal/UnZip.py
parentNew extractor: UnTar (diff)
downloadpyload-d8096353ba12d9e507c1e574f79b9fbff2a1df02.tar.xz
Update extractors (1)
Diffstat (limited to 'module/plugins/internal/UnZip.py')
-rw-r--r--module/plugins/internal/UnZip.py62
1 files changed, 26 insertions, 36 deletions
diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py
index ff929ae00..50ab80da3 100644
--- a/module/plugins/internal/UnZip.py
+++ b/module/plugins/internal/UnZip.py
@@ -2,26 +2,30 @@
from __future__ import with_statement
-import os
import sys
import zipfile
from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError
+from module.plugins.internal.misc import encode
class UnZip(Extractor):
__name__ = "UnZip"
__type__ = "extractor"
- __version__ = "1.20"
+ __version__ = "1.21"
__status__ = "stable"
- __description__ = """Zip extractor plugin"""
+ __description__ = """ZIP extractor plugin"""
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- VERSION = "%s.%s.%s" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
- EXTENSIONS = [".zip", ".zip64"]
+ VERSION = "%s.%s.%s" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
+
+
+ @classmethod
+ def isarchive(cls, filename):
+ return zipfile.is_zipfile(encode(filename))
@classmethod
@@ -30,49 +34,35 @@ class UnZip(Extractor):
def list(self, password=None):
- with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z:
+ with zipfile.ZipFile(self.target, 'r') as z:
z.setpassword(password)
return z.namelist()
def verify(self, password=None):
- with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z:
- z.setpassword(password)
-
- try:
- badfile = z.testzip()
-
- except RuntimeError, e:
- if "encrypted" in e.args[0] or "Bad password" in e.args[0]:
- raise PasswordError
- else:
- raise CRCError("Archive damaged")
-
- else:
- if badfile:
- raise CRCError(badfile)
-
-
-
- def extract(self, password=None):
try:
- with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z:
+ with zipfile.ZipFile(self.target, 'r') as z:
z.setpassword(password)
-
- badfile = z.testzip()
-
- if badfile:
+ if z.testzip():
raise CRCError(badfile)
- else:
- z.extractall(self.out)
except (zipfile.BadZipfile, zipfile.LargeZipFile), e:
raise ArchiveError(e)
except RuntimeError, e:
if "encrypted" in e.args[0] or "Bad password" in e.args[0]:
- raise PasswordError
+ raise PasswordError(e)
else:
- raise ArchiveError(e)
- else:
- self.files = z.namelist()
+ raise CRCError(e)
+
+
+ def extract(self, password=None):
+ self.verify(password)
+
+ try:
+ with zipfile.ZipFile(self.target, 'r') as z:
+ z.setpassword(password)
+ z.extractall(self.dest)
+
+ except RuntimeError, e:
+ raise ArchiveError(e)