Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Oct 30, 2023
1 parent 023b666 commit 4cd8886
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
13 changes: 1 addition & 12 deletions synapseclient/core/upload/multipart_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import concurrent.futures
from contextlib import contextmanager
import hashlib
import json
import math
import mimetypes
Expand All @@ -30,7 +29,7 @@
SynapseUploadAbortedException,
SynapseUploadFailedException,
)
from synapseclient.core.utils import md5_for_file, MB, Spinner
from synapseclient.core.utils import md5_fn, md5_for_file, MB, Spinner

# AWS limits
MAX_NUMBER_OF_PARTS = 10000
Expand Down Expand Up @@ -478,11 +477,6 @@ def multipart_upload_file(
def part_fn(part_number):
return _get_file_chunk(file_path, part_number, part_size)

def md5_fn(part, _):
md5 = hashlib.new("md5", usedforsecurity=False)
md5.update(part)
return md5.hexdigest()

return _multipart_upload(
syn,
dest_file_name,
Expand Down Expand Up @@ -530,11 +524,6 @@ def multipart_upload_string(
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
"""

def md5_fn(part, _):
md5 = hashlib.new("md5", usedforsecurity=False)
md5.update(part)
return md5.hexdigest()

data = text.encode("utf-8")
file_size = len(data)
md5_hex = md5_fn(data, None)
Expand Down
12 changes: 12 additions & 0 deletions synapseclient/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ def md5_for_file(filename, block_size=2 * MB, callback=None):
return md5


def md5_fn(part, _):
"""Calculate the MD5 of a file-like object.
:part -- A file-like object to read from.
:returns: The MD5
"""
md5 = hashlib.new("md5", usedforsecurity=False)
md5.update(part)
return md5.hexdigest()


def download_file(url, localFilepath=None):
"""
Downloads a remote file.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/synapseclient/core/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def thread_get_and_update_file_from_Project(
syn.logger.warning(
f"thread_get_and_update_file_from_Project()::get_all_ids_from_Project timed out, [project: {project.id}]"
)
if len(id) <= 0:
if len(id) == 0:
sleep_for_a_bit()
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def test_command_get_recursive_and_query(test_state):

schema1 = test_state.syn.store(
Schema(
name="Foo Table_test_command_get_recursive_and_query",
name=str(uuid.uuid4()),
columns=cols,
parent=project_entity,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
pool_provider,
UploadAttempt,
)


def md5_fn(part, _):
md5 = hashlib.new("md5", usedforsecurity=False)
md5.update(part)
return md5.hexdigest()
from synapseclient.core.utils import md5_fn


class TestUploadAttempt:
Expand Down

0 comments on commit 4cd8886

Please sign in to comment.