Skip to content

Commit

Permalink
chore: tidy flow control in checksum lookups / usage (#255)
Browse files Browse the repository at this point in the history
Co-authored-by: cojenco <cathyo@google.com>
  • Loading branch information
tseaver and cojenco authored Aug 25, 2021
1 parent a7ae872 commit fcc24fc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion google/_async_resumable_media/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _prepare_request(self, data, metadata, content_type):

checksum_object = sync_helpers._get_checksum_object(self._checksum_type)

if checksum_object:
if checksum_object is not None:
checksum_object.update(data)
actual_checksum = sync_helpers.prepare_checksum_digest(
checksum_object.digest()
Expand Down
9 changes: 2 additions & 7 deletions google/_async_resumable_media/requests/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ async def _write_to_stream(self, response):
self._stream.write(chunk)
local_checksum_object.update(chunk)

if expected_checksum is None:
return

else:
if expected_checksum is not None:
actual_checksum = sync_helpers.prepare_checksum_digest(
checksum_object.digest()
)
Expand Down Expand Up @@ -216,9 +213,7 @@ async def _write_to_stream(self, response):
self._stream.write(chunk)
checksum_object.update(chunk)

if expected_checksum is None:
return
else:
if expected_checksum is not None:
actual_checksum = sync_helpers.prepare_checksum_digest(
checksum_object.digest()
)
Expand Down
2 changes: 1 addition & 1 deletion google/resumable_media/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _prepare_request(self, data, metadata, content_type):
raise TypeError("`data` must be bytes, received", type(data))

checksum_object = _helpers._get_checksum_object(self._checksum_type)
if checksum_object:
if checksum_object is not None:
checksum_object.update(data)
actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest())
metadata_key = _helpers._get_metadata_key(self._checksum_type)
Expand Down
8 changes: 2 additions & 6 deletions google/resumable_media/requests/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def _write_to_stream(self, response):
self._stream.write(chunk)
local_checksum_object.update(chunk)

if expected_checksum is None:
return
else:
if expected_checksum is not None:
actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest())
if actual_checksum != expected_checksum:
msg = _CHECKSUM_MISMATCH.format(
Expand Down Expand Up @@ -242,9 +240,7 @@ def _write_to_stream(self, response):
checksum_object.update(chunk)
response._content_consumed = True

if expected_checksum is None:
return
else:
if expected_checksum is not None:
actual_checksum = _helpers.prepare_checksum_digest(checksum_object.digest())

if actual_checksum != expected_checksum:
Expand Down

0 comments on commit fcc24fc

Please sign in to comment.