<commit_before>import cybox
import cybox.bindings.cybox_common as common_binding
from cybox.common.properties import HexBinary, String
from cybox.common.vocabs import VocabString


class HashName(VocabString):
    _XSI_TYPE = 'cyboxVocabs:HashNameVocab-1.0'


class Hash(cybox.Entity):
    TYPE_MD5 = "MD5"
    TYPE_MD6 = "MD6"
    TYPE_SHA1 = "SHA1"
    TYPE_SHA256 = "SHA256"
    TYPE_SSDEEP = "SSDEEP"
    TYPE_OTHER = "Other"

    def __init__(self, hash_value=None, type_=None, exact=False):
        """Create a new Hash Object

        If exact=True, add 'condition="Equals"' to the hash_value
        """
        # Set type_ first so that auto-typing will work.
        self.type_ = type_
        self.simple_hash_value = hash_value
        self.fuzzy_hash_value = None

        if exact and self.simple_hash_value:
            self.simple_hash_value.condition = "Equals"

    def __str__(self):
        return str(self.simple_hash_value)

    # Properties
    @property
    def type_(self):
        return self._type

    @type_.setter
    def type_(self, value):
        if value and not isinstance(value, HashName):
            value = HashName(value)
        self._type = value

    @property
    def simple_hash_value(self):
        return self._simple_hash_value

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

        # Attempt to determine the hash type if `type_` is None
        if self._simple_hash_value and not self.type_:
            val = self._simple_hash_value.value
            if not val:
                # If not provided or an empty string, don't assign the type
                self.type_ = None
            elif len(val) == 32:
                self.type_ = Hash.TYPE_MD5
            elif len(val) == 40:
                self.type_ = Hash.TYPE_SHA1
            elif len(val) == 64:
                self.type_ = Hash.TYPE_SHA256
            else:
                self.type_ = Hash.TYPE_OTHER

    # Other_Type and FuzzyHashes not yet supported.

    # Import/Export
    def to_obj(self, object_type = None):
        if not object_type:
            hashobj = common_binding.HashType()
        else:
            hashobj = object_type
        if self.type_ is not None: hashobj.set_Type(self.type_.to_obj())
        if self.simple_hash_value is not None : hashobj.set_Simple_Hash_Value(self.simple_hash_value.to_obj())
        if self.fuzzy_hash_value is not None : hashobj.set_Fuzzy_Hash_Value(self.fuzzy_hash_value.to_obj())
        return hashobj

    def to_dict(self):
        hash_dict = {}
        if self.type_ is not None:
            hash_dict['type'] = self.type_.to_dict()
        if self.simple_hash_value is not None:
            hash_dict['simple_hash_value'] = self.simple_hash_value.to_dict()
        if self.fuzzy_hash_value is not None:
            hash_dict['fuzzy_hash_value'] = self.fuzzy_hash_value.to_dict()

        return hash_dict

    @staticmethod
    def from_obj(hash_obj, object_class = None):
        if not hash_obj:
            return None
        if not object_class:
            hash_ = Hash()
        else:
            hash_ = object_class
        hash_.type_ = HashName.from_obj(hash_obj.get_Type())
        hash_.simple_hash_value = HexBinary.from_obj(hash_obj.get_Simple_Hash_Value())
        hash_.fuzzy_hash_value = String.from_obj(hash_obj.get_Fuzzy_Hash_Value())
        return hash_

    @staticmethod
    def from_dict(hash_dict, object_class):
        if not hash_dict:
            return None
        if not object_class:<commit_msg>Add default parameter that keeps tests from failing<commit_after>import cybox
import cybox.bindings.cybox_common as common_binding
from cybox.common.properties import HexBinary, String
from cybox.common.vocabs import VocabString


class HashName(VocabString):
    _XSI_TYPE = 'cyboxVocabs:HashNameVocab-1.0'


class Hash(cybox.Entity):
    TYPE_MD5 = "MD5"
    TYPE_MD6 = "MD6"
    TYPE_SHA1 = "SHA1"
    TYPE_SHA256 = "SHA256"
    TYPE_SSDEEP = "SSDEEP"
    TYPE_OTHER = "Other"

    def __init__(self, hash_value=None, type_=None, exact=False):
        """Create a new Hash Object

        If exact=True, add 'condition="Equals"' to the hash_value
        """
        # Set type_ first so that auto-typing will work.
        self.type_ = type_
        self.simple_hash_value = hash_value
        self.fuzzy_hash_value = None

        if exact and self.simple_hash_value:
            self.simple_hash_value.condition = "Equals"

    def __str__(self):
        return str(self.simple_hash_value)

    # Properties
    @property
    def type_(self):
        return self._type

    @type_.setter
    def type_(self, value):
        if value and not isinstance(value, HashName):
            value = HashName(value)
        self._type = value

    @property
    def simple_hash_value(self):
        return self._simple_hash_value

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

        # Attempt to determine the hash type if `type_` is None
        if self._simple_hash_value and not self.type_:
            val = self._simple_hash_value.value
            if not val:
                # If not provided or an empty string, don't assign the type
                self.type_ = None
            elif len(val) == 32:
                self.type_ = Hash.TYPE_MD5
            elif len(val) == 40:
                self.type_ = Hash.TYPE_SHA1
            elif len(val) == 64:
                self.type_ = Hash.TYPE_SHA256
            else:
                self.type_ = Hash.TYPE_OTHER

    # Other_Type and FuzzyHashes not yet supported.

    # Import/Export
    def to_obj(self, object_type = None):
        if not object_type:
            hashobj = common_binding.HashType()
        else:
            hashobj = object_type
        if self.type_ is not None: hashobj.set_Type(self.type_.to_obj())
        if self.simple_hash_value is not None : hashobj.set_Simple_Hash_Value(self.simple_hash_value.to_obj())
        if self.fuzzy_hash_value is not None : hashobj.set_Fuzzy_Hash_Value(self.fuzzy_hash_value.to_obj())
        return hashobj

    def to_dict(self):
        hash_dict = {}
        if self.type_ is not None:
            hash_dict['type'] = self.type_.to_dict()
        if self.simple_hash_value is not None:
            hash_dict['simple_hash_value'] = self.simple_hash_value.to_dict()
        if self.fuzzy_hash_value is not None:
            hash_dict['fuzzy_hash_value'] = self.fuzzy_hash_value.to_dict()

        return hash_dict

    @staticmethod
    def from_obj(hash_obj, object_class = None):
        if not hash_obj:
            return None
        if not object_class:
            hash_ = Hash()
        else:
            hash_ = object_class
        hash_.type_ = HashName.from_obj(hash_obj.get_Type())
        hash_.simple_hash_value = HexBinary.from_obj(hash_obj.get_Simple_Hash_Value())
        hash_.fuzzy_hash_value = String.from_obj(hash_obj.get_Fuzzy_Hash_Value())
        return hash_

    @staticmethod
    def from_dict(hash_dict, object_class=None):
        if not hash_dict:
            return None
        if not object_class:
{'fraction_non_alphanumeric': 0.07955310270561314, 'fraction_numerical': 0.006730380939561179, 'mean_word_length': 2.322898032200358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3672829', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2273, 'n_words': 540}