import binascii
import re


def humanhexlify(data, n=-1):
    """Hexlify given data with 1 space char btw hex values for easier reading for humans
    :param data: binary data to hexlify
    :param n: If n is a positive integer then shorten the output of this function to n hexlified bytes.

    Input like
        'ab\x04ce'
    becomes
        '61 62 04 63 65'

    With n=3 input like
        data='ab\x04ce', n=3
    becomes
        '61 62 04 ...'
    """
    tail = b' ...' if 0 < n < len(data) else b''
    if tail:
        data = data[:n]
    hx = binascii.hexlify(data)
    return b' '.join(re.findall(b'..', hx)) + tail