def verify(self, password=None): try: with zipfile.ZipFile(self.filename, "r") as z: z.setpassword(password) badfile = z.testzip() if badfile is not None: raise CRCError(badfile) except (zipfile.BadZipfile, zipfile.LargeZipFile) as exc: raise ArchiveError(exc) except RuntimeError as exc: if "encrypted" in exc.args[0] or "Bad password" in exc.args[0]: raise PasswordError(exc) else: raise CRCError(exc)
def extract(self, password=None): command = "x" if self.fullpath else "e" p = self.call_cmd(command, self.filename, self.dest, password=password) #: Communicate and retrieve stderr self.progress(p) out, err = (to_str(r).strip() if r else "" for r in p.communicate()) if err: if self._RE_BADPWD.search(err): raise PasswordError elif self._RE_BADCRC.search(err): raise CRCError(err) elif self.config.get("ignore_warnings", False) and err.startswith( "WARNING:" ): pass else: #: Raise error if anything is on stderr raise ArchiveError(err) if p.returncode: raise ArchiveError(self._("Process return code: {}").format(p.returncode)) return self.list(password)
def verify(self, password=None): #: 7z can't distinguish crc and pw error in test p = self.call_cmd("l", "-slt", self.filename) out, err = (to_str(r).strip() if r else "" for r in p.communicate()) if self._RE_BADPWD.search(out): raise PasswordError elif self._RE_BADPWD.search(err): raise PasswordError elif self._RE_BADCRC.search(out): raise CRCError(self._("Header protected")) elif self._RE_BADCRC.search(err): raise CRCError(err)
def verify(self, password=None): try: t = tarfile.open(self.filename, errorlevel=1) except tarfile.CompressionError as exc: raise CRCError(exc) except (OSError, tarfile.TarError) as exc: raise ArchiveError(exc) else: t.close()
def verify(self, password=None): p = self.call_cmd("l", "-v", self.filename, password=password) out, err = (to_str(r).strip() if r else "" for r in p.communicate()) if self._RE_BADPWD.search(err): raise PasswordError if self._RE_BADCRC.search(err): raise CRCError(err) #: Output is only used to check if password protected files are present for groups in self._RE_FILES.findall(out): if groups[0] == "*": raise PasswordError
def extract(self, password=None): self.verify(password) try: with tarfile.open(self.filename, errorlevel=2) as t: t.extractall(self.dest) self.files = t.getnames() return self.files except tarfile.ExtractError as exc: self.log_warning(exc) except tarfile.CompressionError as exc: raise CRCError(exc) except (OSError, tarfile.TarError) as exc: raise ArchiveError(exc)
def extract(self, password=None): command = "x" if self.fullpath else "e" p = self.call_cmd(command, "-o" + self.dest, self.filename, password=password) #: Communicate and retrieve stderr self.progress(p) out, err = (to_str(r).strip() if r else "" for r in p.communicate()) if err: if self._RE_BADPWD.search(err): raise PasswordError elif self._RE_BADCRC.search(err): raise CRCError(err) else: #: Raise error if anything is on stderr raise ArchiveError(err) if p.returncode > 1: raise ArchiveError(self._("Process return code: {}").format(p.returncode))