def get_releases_hashes(releases, algorithm, verbose=False): for found in releases: digests = found["digests"] try: found["hash"] = digests[algorithm] if verbose: _verbose("Found hash for", found["url"]) except KeyError: # The algorithm is NOT in the 'digests' dict. # We have to download the file and use pip url = found["url"] if verbose: _verbose("Found URL", url) download_dir = tempfile.gettempdir() filename = os.path.join(download_dir, os.path.basename(url.split("#")[0])) if not os.path.isfile(filename): if verbose: _verbose(" Downloaded to", filename) with open(filename, "wb") as f: f.write(_download(url, binary=True)) elif verbose: _verbose(" Re-using", filename) found["hash"] = pip_api.hash(filename, algorithm) if verbose: _verbose(" Hash", found["hash"]) yield {"hash": found["hash"]}
def get_releases_hashes(releases, algorithm, verbose=False): for found in releases: url = found['url'] if verbose: _verbose('Found URL', url) digests = found['digests'] try: found['hash'] = digests[algorithm] except KeyError: # The algorithm is NOT in the 'digests' dict. # We have to download the file and use pip download_dir = tempfile.gettempdir() filename = os.path.join(download_dir, os.path.basename(url.split('#')[0])) if not os.path.isfile(filename): if verbose: _verbose(' Downloaded to', filename) with open(filename, 'wb') as f: f.write(_download(url, binary=True)) elif verbose: _verbose(' Re-using', filename) found['hash'] = pip_api.hash(filename, algorithm) if verbose: _verbose(' Hash', found['hash']) yield {'url': url, 'hash': found['hash']}
def test_hash_invalid_algorithm(): with pytest.raises(pip_api.exceptions.InvalidArguments): pip_api.hash("whatever", "invalid")
def test_hash_default_algorithm_is_256(some_distribution): sha256 = "cce4031ec744585688ddab649427133ac22396da29ad82fdbd11692c3a26fe19" assert pip_api.hash(some_distribution.filename) == sha256
def test_hash(some_distribution, algorithm, expected): result = pip_api.hash(some_distribution.filename, algorithm=algorithm) assert result == expected
def test_hash_default_algorithm_is_256(some_distribution): sha256 = 'c3ebc5b7bc06d4466d339f4d8d1e61d1fdc256dd913d6d5752acea9ce5581a15' assert pip_api.hash(some_distribution.filename) == sha256
def test_hash_default_algorithm_is_256(some_distribution): sha256 = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' assert pip_api.hash(some_distribution.filename) == sha256