Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/pypi/client.py
Show First 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | def prepare_release_artifact(self, project, release, artifact): | ||||
length = int(r.headers['content-length']) | length = int(r.headers['content-length']) | ||||
if length != artifact['size']: | if length != artifact['size']: | ||||
raise ValueError('Error when checking size: %s != %s' % ( | raise ValueError('Error when checking size: %s != %s' % ( | ||||
artifact['size'], length)) | artifact['size'], length)) | ||||
h = hashutil.MultiHash(length=length) | h = hashutil.MultiHash(length=length) | ||||
with open(filepath, 'wb') as f: | with open(filepath, 'wb') as f: | ||||
for chunk in r.iter_content(): | for chunk in r.iter_content(chunk_size=None): | ||||
h.update(chunk) | h.update(chunk) | ||||
f.write(chunk) | f.write(chunk) | ||||
hashes = h.hexdigest() | hashes = h.hexdigest() | ||||
actual_digest = hashes['sha256'] | actual_digest = hashes['sha256'] | ||||
if actual_digest != artifact['sha256']: | if actual_digest != artifact['sha256']: | ||||
raise ValueError( | raise ValueError( | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |