def slack_chars(payload, source, target, finalize=False):
    if (source in payload['data']):
        payload['diff'] += (len(source) - len(target))
        payload['data'] = payload['data'].replace(source, target)
    if finalize:
        slacks = [b'\r\nAccept-Encoding: gzip, deflate', b'\r\nConnection: Keep-Alive']
        payload['diff'] += len(slacks[0])
        payload['data'] = payload['data'].replace(slacks[0], b'')
        for slack in slacks[1:]:
            if (payload['diff'] < 0):
                payload['diff'] += len(slack)
                payload['data'] = payload['data'].replace(slack, b'')
        if (payload['diff'] > 7):
            header = b'\r\nID: '
            stuff = b''.join((bytes(random.choice((string.ascii_uppercase + string.digits)), 'ascii') for _ in range((payload['diff'] - len(header)))))
            payload['data'] = ((payload['data'][:(- 4)] + header) + stuff)
        else:
            payload['data'] = (payload['data'][:(- 4)] + b' '.join((b'' for _ in range(payload['diff']))))
        payload['data'] = (payload['data'] + b'\r\n\r\n')
        payload['diff'] = 0
    return payload
def slack_chars(payload, source, target, finalize=False):
    if (source in payload['data']):
        payload['diff'] += (len(source) - len(target))
        payload['data'] = payload['data'].replace(source, target)
    if finalize:
        slacks = [b'\r\nAccept-Encoding: gzip, deflate', b'\r\nConnection: Keep-Alive']
        payload['diff'] += len(slacks[0])
        payload['data'] = payload['data'].replace(slacks[0], b)
        for slack in slacks[1:]:
            if (payload['diff'] < 0):
                payload['diff'] += len(slack)
                payload['data'] = payload['data'].replace(slack, b)
        if (payload['diff'] > 7):
            header = b'\r\nID: '
            stuff = b.join((bytes(random.choice((string.ascii_uppercase + string.digits)), 'ascii') for _ in range((payload['diff'] - len(header)))))
            payload['data'] = ((payload['data'][:(- 4)] + header) + stuff)
        else:
            payload['data'] = (payload['data'][:(- 4)] + b' '.join((b for _ in range(payload['diff']))))
        payload['data'] = (payload['data'] + b'\r\n\r\n')
        payload['diff'] = 0
    return payload