<commit_before>"""
    util.py
    ~~~~~~~~~~~~
    contains utility functions.
"""

import hashlib
from datetime import datetime


# Classes

def get_timestamp():
    return datetime.utcnow()

class Key(object):
    """ A simple object for adding aditional properties to keys """

    def __init__(self, key=None, node_hash=None):
        self.key = key
        self.node_hash  = node_hash

    def __hash__(self):
        return self.key.__hash__()

class Value(object):
    """ A simple object for adding aditional properties to values """

    def __init__(self, value=None, timestamp=None):
        self.value = value
        if not timestamp:
            self.timestamp = get_timestamp()
        else:
            self.timestamp = timestamp

class ErrorCode(object):
    """ Object for passing around error codes from put/get/delete commands"""
    def __init__(self, error_code='\x00'):
        self.error_code = error_code

    def __eq__(self, other):
        return self.error_code == other.error_code

    def __nonzero__(self):
        if self.error_code == '\x00':
            return True
        else:
            return False

    def get_error_message(self):
        """returns a human-readable message for a given error."""
        try:
            return{
                '\x00': "Error code: {}.  Operation successful.".format([error_code]),
                '\x01': "Error code: {}.  Inexistant key.".format([error_code]),
                '\x02': "Error code: {}.  MemoryError.".format([error_code]),
                '\x03': "Error code: {}.  System overload.".format([error_code]),
                '\x04': "Error code: {}.  Internal KVStore failure.".format([error_code]),
                '\x05': "Error code: {}.  Unrecognized command.".format([error_code]),
                '\x06': "Error code: {}.  Unrecognized error: {}.".format([error_code], sys.exc_info()[0])
            }[self.error_code]
        except KeyError:
            self.logger.warn('Error code %s not found.', error, exc_info=True)
<commit_msg>Add get_hash to util<commit_after>"""
    util.py
    ~~~~~~~~~~~~
    contains utility functions.
"""

import hashlib
from datetime import datetime

def get_hash(value):
    return hashlib.sha256(value).hexdigest()

# Classes

def get_timestamp():
    return datetime.utcnow()

class Key(object):
    """ A simple object for adding aditional properties to keys """

    def __init__(self, key=None, node_hash=None):
        self.key = key
        self.node_hash  = node_hash

    def __hash__(self):
        return self.key.__hash__()

class Value(object):
    """ A simple object for adding aditional properties to values """

    def __init__(self, value=None, timestamp=None):
        self.value = value
        if not timestamp:
            self.timestamp = get_timestamp()
        else:
            self.timestamp = timestamp

class ErrorCode(object):
    """ Object for passing around error codes from put/get/delete commands"""
    def __init__(self, error_code='\x00'):
        self.error_code = error_code

    def __eq__(self, other):
        return self.error_code == other.error_code

    def __nonzero__(self):
        if self.error_code == '\x00':
            return True
        else:
            return False

    def get_error_message(self):
        """returns a human-readable message for a given error."""
        try:
            return{
                '\x00': "Error code: {}.  Operation successful.".format([error_code]),
                '\x01': "Error code: {}.  Inexistant key.".format([error_code]),
                '\x02': "Error code: {}.  MemoryError.".format([error_code]),
                '\x03': "Error code: {}.  System overload.".format([error_code]),
                '\x04': "Error code: {}.  Internal KVStore failure.".format([error_code]),
                '\x05': "Error code: {}.  Unrecognized command.".format([error_code]),
                '\x06': "Error code: {}.  Unrecognized error: {}.".format([error_code], sys.exc_info()[0])
            }[self.error_code]
        except KeyError:
            self.logger.warn('Error code %s not found.', error, exc_info=True)

{'fraction_non_alphanumeric': 0.13692344844240523, 'fraction_numerical': 0.009900990099009901, 'mean_word_length': 2.367479674796748, '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': '1726159', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1154, 'n_words': 317}