import hashlib


def get_hashfunc_by_name(name, data):
    """
    Get a callable hashfunc by name.

    This function can be used directly or with functools.partial, for example:

    >>> hashfunc = functools.partial(get_hashfunc_by_name, 'sha256')
    >>> hashfunc('sir robin').digest()

    Args:
        name (str): The string name of the desired algorithm
        data (buffer): The buffer to hash
    Returns:
        callable: The callable hash function of the provided
            algorithm updated with the data to be hashed
    """
    hashfunc = hashlib.new(name)
    hashfunc.update(data)
    return hashfunc