def verify(self, sha1=None): _dlsize = getsize(self._destination) if self.get_size() != -1 and _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: return None checksum = hashlib.sha1() with io.open(self._destination, "rb", buffering=0) as fp: while True: chunk = fp.read(io.DEFAULT_BUFFER_SIZE) if not chunk: break checksum.update(chunk) if sha1.lower() != checksum.hexdigest().lower(): raise FDSHASumMismatch(checksum.hexdigest(), self._fname, sha1) return True
def verify(self, sha1=None): _dlsize = getsize(self._destination) if _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: return dlsha1 = None try: dlsha1 = check_output(["sha1sum", self._destination]) except OSError: try: dlsha1 = check_output(["shasum", "-a", "1", self._destination]) except OSError: pass if dlsha1: dlsha1 = dlsha1[1:41] if dlsha1.startswith("\\") else dlsha1[:40] if sha1 != dlsha1: raise FDSHASumMismatch(dlsha1, self._fname, sha1)
def verify(self, sha1=None): _dlsize = getsize(self._destination) if _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: return dlsha1 = None try: res = check_output(["sha1sum", self._destination]) dlsha1 = res[:40] except OSError: try: res = check_output(["shasum", "-a", "1", self._destination]) dlsha1 = res[:40] except OSError: pass if dlsha1 and sha1 != dlsha1: raise FDSHASumMismatch(dlsha1, self._fname, sha1)
def verify(self, sha1=None): _dlsize = getsize(self._destination) if self.get_size() != -1 and _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: return dlsha1 = None try: result = util.exec_command(["sha1sum", self._destination]) dlsha1 = result['out'] except (OSError, ValueError): try: result = util.exec_command( ["shasum", "-a", "1", self._destination]) dlsha1 = result['out'] except (OSError, ValueError): pass if dlsha1: dlsha1 = dlsha1[1:41] if dlsha1.startswith("\\") else dlsha1[:40] if sha1 != dlsha1: raise FDSHASumMismatch(dlsha1, self._fname, sha1)