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

Code cleanups and simplifications. #446

Merged
merged 2 commits into from
Dec 26, 2016

Conversation

donatello
Copy link
Member

No description provided.

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

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

CI fails. Please look into that.

@donatello
Copy link
Member Author

@balamurugana CI failure is fixed. It was some kind of intermittent problem in the CI, and not in the change itself. Got fixed after a force push.

@balamurugana
Copy link
Member

👍

@harshavardhana
Copy link
Member

Two comments..

@donatello
Copy link
Member Author

@harshavardhana

This will fail on windows. We need to explicitly close the file. Can you validate ?

No it should not. The with statement was introduced a long time back (in Py 2.5 https://docs.python.org/3/whatsnew/2.6.html#pep-343-the-with-statement and more powerful in py 3 - https://docs.python.org/3/reference/compound_stmts.html#with ) and is meant to do things like close files that is alternatively done with same guarantee with try...catch...finally block (just calling f.close() after the with statement would not have the same effect - in case there was a bug in windows - because of exceptions).

I tried to find if there are any bug reports related to Windows and closing files and the with statement, but I didn't see any. If there was such a bug, it would be quite serious and there would be multiple reports.

Why a strict bytes type ?

In the case of fput_object this is not a problem, since our code opens the file in binary mode and this returns only bytes.

In put_object, the data returned by the io.RawIOBase instance, could return even str (unicode) streams, as they are user provided. How the unicode stream should be stored on disk requires us to know what encoding is intended by the user - it is not necessarily utf-8 (user may intend utf-16, etc). To avoid any unintended encoding of file-data we accept only bytes - this makes sure that the user encodes it to bytes and then calls put_object.

In other situations it is ok for us to encode str type to utf-8 and convert to bytes, as in the library, we know what data we are encoding in all other situations.

@donatello
Copy link
Member Author

Added a comment explaining why we accept only strict bytes in _do_put_object.

policy[1] + '","' + policy[2] + '"]')
policies = self.policies
if self._content_length_range:
policies.append(['content-length-range'] +
Copy link
Member

Choose a reason for hiding this comment

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

Why not do this inside set_content_length_range()

Copy link
Member Author

Choose a reason for hiding this comment

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

We probably could do this (and also the expiration time change/comment), but I prefer to do these changes in another refactor - the reason is that I am not sure the current PostPolicy API is cleanly done.

The current implementation has all its methods names like set_expires, set_key_startswith, etc but the name set_* implies that if we do the operation repeatedly, only the last value/call has effect - but the implementation does not satisfy this natural expectation - if we call set_bucket_name twice, it will append two conditions to the policy, possibly rendering it invalid - in the S3 spec, it seems these policy conditions are conjunctive (AND-ed together). However, the expiration condition, and the content length condition are ok to be set repeatedly to different values, and the programmer's intention is satisfied by the library implementation. I want to make this behaviour consistent in a (near) future refactor.

Copy link
Member

Choose a reason for hiding this comment

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

The current implementation has all its methods names like set_expires, set_key_startswith, etc but the name set_* implies that if we do the operation repeatedly, only the last value/call has effect - but the implementation does not satisfy this natural expectation - if we call set_bucket_name twice, it will append two conditions to the policy, possibly rendering it invalid - in the S3 spec, it seems these policy conditions are conjunctive (AND-ed together).

To solve this problem we need to fix that first, this has to be done perhaps in all libraries FWICS.

str(self._content_length_range[0]) +
', ' + str(self._content_length_range[1]) + ']')
policy_stmt = {
"expiration": self._expiration.strftime(
Copy link
Member

Choose a reason for hiding this comment

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

why not do this in set_expires?

Copy link
Member Author

Choose a reason for hiding this comment

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

See reply in comment about content-length-range.

import collections
import fnmatch
import itertools

from .compat import basestring
Copy link
Member

Choose a reason for hiding this comment

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

can you update the licence header for these files as well pointing to '2015, 2016'.

Copy link
Member

Choose a reason for hiding this comment

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

Do it wherever you are cleaning up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@harshavardhana harshavardhana merged commit 9c2224b into minio:master Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants