Read a line and return it.  If "raise_exception" is set,
        raise _ConnectionDeadError if the read fails, otherwise return
        an empty string.

def readline(self, raise_exception=False):
        """Read a line and return it.  If "raise_exception" is set,
        raise _ConnectionDeadError if the read fails, otherwise return
        an empty string.
        """
        buf = self.buffer
        if self.socket:
            recv = self.socket.recv
        else:
            recv = lambda bufsize: ''

        while True:
            index = buf.find('\r\n')
            if index >= 0:
                break
            data = recv(4096)
            if not data:
                # connection close, let's kill it and raise
                self.mark_dead('connection closed in readline()')
                if raise_exception:
                    raise _ConnectionDeadError()
                else:
                    return ''

            buf += data
        self.buffer = buf[index+2:]
        return buf[:index]