def has_error(self): """ @return: @rtype: bool """ ret = False for response in self.bulk_responses: if response.has_error(): ret = True break return ret
def get_error(self): """ Returns the first found error @return: @rtype: self """ error = "" for response in self.bulk_responses: if response.has_error(): error = response.get_error() break return error
def get_error(self): """ Returns the first found error @return: @rtype: self """ error = '' for response in self.bulk_responses: if response.has_error(): error = response.get_error() break return error
def execute(self, request, params): """ Executes a transport request @param request: request object @type request: pylastica.request.Request @param params: hostname, port, path, etc. @type params: dict @return: @rtype: pylastica.response.Response """ connection = self.connection send_timeout = int(connection.get_config('send_timeout')) if connection.has_config('send_timeout') else None recv_timeout = int(connection.get_config('recv_timeout')) if connection.has_config('recv_timeout') else None framed_transport = bool(connection.get_config('framed_transport')) if connection.has_config('framed_transport') else False try: client = self._get_client(connection.host, connection.port, send_timeout, recv_timeout, framed_transport) rest_request = Rest.RestRequest() rest_request.method = Rest.Method._NAMES_TO_VALUES[request.get_method()] rest_request.uri = request.path query = request.query if query is not None: rest_request.parameters = query data = request.get_data() if data is not None: if isinstance(data, dict): content = json.dumps(data) else: content = data rest_request.body = content result = client.execute(rest_request) response = pylastica.response.Response(result.body) except thrift.Thrift.TException as e: response = pylastica.response.Response('') raise pylastica.exception.connection.ThriftException(e, request, response) if response.has_error(): raise pylastica.exception.ResponseException(request, response) return response