def _start(self, term, **global_opt_args): token = self.next_token self.next_token += 1 # Construct query query = p.Query() query.type = p.Query.START query.token = token # Set global opt args # The 'db' option will default to this connection's default # if not otherwise specified. if 'db' in global_opt_args: global_opt_args['db'] = DB(global_opt_args['db']) else: if self.db: global_opt_args['db'] = DB(self.db) for k,v in global_opt_args.iteritems(): pair = query.global_optargs.add() pair.key = k expr(v).build(pair.val) # Compile query to protobuf term.build(query.query) return self._send_query(query, term, global_opt_args)
def handle(self): magic = self.request.recv(4) (length, ) = struct.unpack("<L", self.request.recv(4)) if length != 0: self.request.recv(length) self.request.sendall("SUCCESS\0") while (True): header = self.request.recv(4) if len(header) == 0: break (length, ) = struct.unpack("<L", header) data = self.request.recv(length) query = p.Query() query.ParseFromString(data) response = p.Response() response.token = query.token response.type = p.Response.SUCCESS_ATOM datum = response.response.add() datum.type = p.Datum.R_NULL response_protobuf = response.SerializeToString() response_header = struct.pack("<L", len(response_protobuf)) self.request.sendall(response_header + response_protobuf)
def _end(self, orig_query, orig_term): query = p.Query() query.type = p.Query.STOP query.token = orig_query.token return self._send_query(query, orig_term)
def _continue(self, orig_query, orig_term, opts): query = p.Query() query.type = p.Query.CONTINUE query.token = orig_query.token return self._send_query(query, orig_term, opts)