def read_response(self):
    response = self._buffer.readline()
    if (not response):
        raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
    (byte, response) = (byte_to_chr(response[0]), response[1:])
    if (byte not in ('-', '+', ':', '$', '*')):
        raise InvalidResponse(('Protocol Error: %s, %s' % (str(byte), str(response))))
    if (byte == '-'):
        response = nativestr(response)
        error = self.parse_error(response)
        if isinstance(error, ConnectionError):
            raise error
        return error
    elif (byte == '+'):
        pass
    elif (byte == ':'):
        response = long(response)
    elif (byte == '$'):
        length = int(response)
        if (length == (- 1)):
            return None
        response = self._buffer.read(length)
    elif (byte == '*'):
        length = int(response)
        if (length == (- 1)):
            return None
        response = [self.read_response() for i in xrange(length)]
    if (isinstance(response, bytes) and self.encoding):
        response = response.decode(self.encoding)
    return response
def read_response(self):
    response = self._buffer.readline()
    if (not response):
        raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
    (byte, response) = (byte_to_chr(response[0]), response[1:])
    if (byte not in ('-', '+', ':', '$', '*')):
        raise InvalidResponse(('Protocol Error: %s, %s' % (str(byte), str(response))))
    if (byte == '-'):
        response = nativestr(response)
        error = self.parse_error(response)
        if isinstance(error, ConnectionError):
            raise error
        return error
    elif (byte == '+'):
        pass
    elif (byte == ':'):
        response = long(response)
    elif (byte == '$'):
        length = int(response)
        if (length == (- 1)):
            return None
        response = self._buffer.read(length)
    elif (byte == '*'):
        length = int(response)
        if (length == (- 1)):
            return None
        response = [self.read_response() for i in xrange(length)]
    if (isinstance(response, bytes) and self.encoding):
        response = response.decode(self.encoding)
    return response