Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid MD5 #1812

Merged
merged 1 commit into from
Mar 1, 2016
Merged

Avoid MD5 #1812

merged 1 commit into from
Mar 1, 2016

Conversation

JordonPhillips
Copy link
Member

Avoid MD5 if it isn't available.

@JordonPhillips JordonPhillips added the pr:needs-review This PR needs a review from a Member. label Feb 26, 2016
if not is_stream:
os.remove(filename)
raise MD5Error(filename)
if md5 and etag != md5.hexdigest():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

md5 is not None

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is falsy, so is that necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Semantically, if you have a value of None, you need to differentiate between "provided a false like value" and "did not provide a value".

Also, from pep8:

Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

@jamesls
Copy link
Member

jamesls commented Feb 27, 2016

Looks good, just had some small comments.

# Setup MD5 patches
self.md5_object = mock.Mock()
self.md5_object.hexdigest = mock.Mock(return_value=etag)
md5_builder = mock.Mock(return_value=self.md5_object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it's more convenient to store these as instance attributes you can also just say:

md5_builder = mock.Mock()
md5_builder.return_value.hexdigest.return_value = etag

That makes it more clear that you're only storing mocks that you plan on asserting things on later.

@jamesls
Copy link
Member

jamesls commented Feb 29, 2016

:shipit:

Avoids attempting to call MD5 functions when it is not accessible.
JordonPhillips added a commit that referenced this pull request Mar 1, 2016
@JordonPhillips JordonPhillips merged commit 6d05c5d into aws:develop Mar 1, 2016
@JordonPhillips JordonPhillips deleted the check-md5 branch March 1, 2016 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:needs-review This PR needs a review from a Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants