def send_buffer(buf, sock, host_id):
    """Utility function that sends the buffer into the provided socket.
    The buffer itself will slowly clear out and is modified in place.
    """
    try:
        timeout = sock.gettimeout()
        sock.setblocking(False)
        try:
            for idx, item in enumerate(buf):
                sent = 0
                while 1:
                    try:
                        sent = sock.send(item)
                    except IOError as e:
                        if e.errno == errno.EAGAIN:
                            continue
                        elif e.errno == errno.EWOULDBLOCK:
                            break
                        raise
                    break
                if len(item) < sent:
                    buf[:idx + 1] = [item[sent:]]
                    break
            else:
                del buf[:]
        finally:
            sock.settimeout(timeout)
    except IOError as e:
        if isinstance(e, socket.timeout):
            raise TimeoutError('Timeout writing to socket (host %s)'
                               % host_id)
        raise ConnectionError('Error while writing to socket (host %s): %s'
                              % (host_id, e))
dataset/ETHPy150Open getsentry/rb/rb/clients.py/send_buffer/swapped operands of `<`