From 5c50047df3377564ac9b2e3cdf12802134d367fd Mon Sep 17 00:00:00 2001 From: Alex Bostock Date: Tue, 20 Feb 2024 17:11:23 +0000 Subject: [PATCH] Refactor for linter / cognitive complexity rule --- scribemi/ScribeMi.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scribemi/ScribeMi.py b/scribemi/ScribeMi.py index a61455f..5630dce 100644 --- a/scribemi/ScribeMi.py +++ b/scribemi/ScribeMi.py @@ -418,10 +418,7 @@ def fetch_model(self, task: MITask): ) res = requests.get(modelUrl) if res.status_code == 200: - md5checksum_expected = res.headers["ETag"].replace('"', "") - md5checksum = md5(res.text.encode(), usedforsecurity=False).hexdigest() - if md5checksum != md5checksum_expected: - raise Exception("Integrity Error: invalid checksum. Please retry.") + verify_etag_checksum(res) return json.loads(res.text) elif res.status_code == 401 or res.status_code == 403: @@ -503,3 +500,10 @@ def upload_file(file, md5checksum, url): res = requests.put(url, data=file, headers={"Content-MD5": md5checksum}) if res.status_code != 200: raise Exception("Error uploading file: {}".format(res.status_code)) + + +def verify_etag_checksum(res: requests.Response): + md5checksum_expected = res.headers["ETag"].replace('"', "") + md5checksum = md5(res.text.encode(), usedforsecurity=False).hexdigest() + if md5checksum != md5checksum_expected: + raise Exception("Integrity Error: invalid checksum. Please retry.")