def _check_response(self, response): query = self.request term = query.term opts = query.global_optargs self._check_error_response(response, term) if response.type in SequenceResponse: # Sequence responses value = Cursor(self, query, opts) value._extend(response) elif response.type == pResponse.SUCCESS_ATOM: # Atom response if len(response.data) < 1: value = None value = recursively_convert_pseudotypes(response.data[0], opts) elif response.type == pResponse.WAIT_COMPLETE: # Noreply_wait response return None else: # Default for unknown response types raise RqlDriverError("Unknown Response type %d encountered in " "response." % response.type) if response.profile is not None: value = {"value": value, "profile": response.profile} return value
def __iter__(self): while True: if len(self.responses) == 0 and self.connection_closed: raise RqlDriverError("Connection closed, cannot read cursor") if len(self.responses) == 0 and not self.end_flag: self.conn._continue_cursor(self) if len(self.responses) == 1 and not self.end_flag: self.conn._async_continue_cursor(self) if len(self.responses) == 0 and self.end_flag: break self.conn._check_error_response(self.responses[0], self.query.term) if self.responses[0].type != p.Response.SUCCESS_PARTIAL and self.responses[0].type != p.Response.SUCCESS_SEQUENCE: raise RqlDriverError("Unexpected response type received for cursor") response_data = recursively_convert_pseudotypes(self.responses[0].data, self.opts) del self.responses[0] for item in response_data: yield item
def _it(self): while True: if len(self.responses) == 0 and self.connection_closed: raise RqlDriverError("Connection closed, cannot read cursor") if len(self.responses) == 0 and not self.end_flag: self.conn._continue_cursor(self) if len(self.responses) == 1 and not self.end_flag: self.conn._async_continue_cursor(self) if len(self.responses) == 0 and self.end_flag: break self.conn._check_error_response(self.responses[0], self.query.term) if self.responses[0].type != pResponse.SUCCESS_PARTIAL and \ self.responses[0].type != pResponse.SUCCESS_SEQUENCE and \ self.responses[0].type != pResponse.SUCCESS_FEED: raise RqlDriverError("Unexpected response type received for cursor") response_data = recursively_convert_pseudotypes(self.responses[0].data, self.opts) del self.responses[0] for item in response_data: yield item
# Get response response = self._read_response(query.token) self._check_error_response(response, query.term) if response.type == pResponse.SUCCESS_PARTIAL or \ response.type == pResponse.SUCCESS_SEQUENCE or \ response.type == pResponse.SUCCESS_FEED: # Sequence responses value = Cursor(self, query, opts) self.cursor_cache[query.token] = value value._extend(response) elif response.type == pResponse.SUCCESS_ATOM: # Atom response if len(response.data) < 1: value = None value = recursively_convert_pseudotypes(response.data[0], opts) elif response.type == pResponse.WAIT_COMPLETE: # Noreply_wait response return None else: # Default for unknown response types raise RqlDriverError("Unknown Response type %d encountered in response." % response.type) if response.profile is not None: value = {"value": value, "profile": response.profile} return value def connect(host='localhost', port=28015, db=None, auth_key="", timeout=20): return Connection(host, port, db, auth_key, timeout)
# Get response response = self._read_response(query.token) self._check_error_response(response, query.term) if response.type == p.Response.SUCCESS_PARTIAL or \ response.type == p.Response.SUCCESS_SEQUENCE or \ response.type == p.Response.SUCCESS_FEED: # Sequence responses value = Cursor(self, query, opts) self.cursor_cache[query.token] = value value._extend(response) elif response.type == p.Response.SUCCESS_ATOM: # Atom response if len(response.data) < 1: value = None value = recursively_convert_pseudotypes(response.data[0], opts) elif response.type == p.Response.WAIT_COMPLETE: # Noreply_wait response return None else: # Default for unknown response types raise RqlDriverError( "Unknown Response type %d encountered in response." % response.type) if response.profile is not None: value = {"value": value, "profile": response.profile} return value