Skip to content

Commit

Permalink
Refactor for linter / cognitive complexity rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbostock committed Feb 20, 2024
1 parent 1ef6ddf commit 5c50047
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scribemi/ScribeMi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.")

0 comments on commit 5c50047

Please sign in to comment.