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

hash object does not set type if value not set on construction #8

Closed
scottquint opened this issue Mar 21, 2013 · 1 comment
Closed
Assignees

Comments

@scottquint
Copy link

simple_hash_value setter was:

@simple_hash_value.setter
def simple_hash_value(self, value):
    if value and not isinstance(value, SimpleHashValue):
        value = SimpleHashValue(value)
    self._simple_hash_value = value

should use same logic as in constructor,as follows:

@simple_hash_value.setter
def simple_hash_value(self, hash_value):
    if hash_value and not isinstance(hash_value, SimpleHashValue):
        hash_value = SimpleHashValue(hash_value)
    self._simple_hash_value = hash_value
    if not hash_value:
        # If not provided or an empty string, don't assign the type
        self.type_ = None
    elif len(hash_value.value) == 32:
        self.type_ = Hash.TYPE_MD5
    elif len(hash_value.value) == 40:
        self.type_ = Hash.TYPE_SHA1
    elif len(hash_value.value) == 64:
        self.type_ = Hash.TYPE_SHA256
    else:
        self.type_ = Hash.TYPE_OTHER
@ghost ghost assigned gtback Mar 21, 2013
@gtback
Copy link
Contributor

gtback commented Mar 25, 2013

I don't think we want the auto-typing to occur every time we set the hash value. The reason is that it is possible to have a TYPE_OTHER hash of length 32, 40, or 64, and we'd want the following two blocks of code to behave identically:

h = Hash()
h.simple_hash_value = "0123456789abcdef0123456789abcdef"
h.type_ = Hash.TYPE_OTHER

and

h2 = Hash()
h2.type_ = Hash.TYPE_OTHER
h2.simple_hash_value = "0123456789abcdef0123456789abcdef"

With this change, then h2.type_ would be set to TYPE_MD5 after the second block. Basically, we never want to modify the type of hash after the user has set it, as this could be potentially unexpected behavior.

I'm going to change the auto-typing feature of the Hash so that it executes whenever the simple_hash_value is modified and the the type_ is set to None (that is, before it has been set by the user).

@gtback gtback closed this as completed in 621d93d Mar 25, 2013
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

No branches or pull requests

2 participants