def get_results(self, client_id, msg):
content = msg['<STR_LIT:content>']<EOL>msg_ids = sorted(set(content['<STR_LIT>']))<EOL>statusonly = content.get('<STR_LIT>', False)<EOL>pending = []<EOL>completed = []<EOL>content = dict(status='<STR_LIT>')<EOL>content['<STR_LIT>'] = pending<EOL>content['<STR_LIT>'] = completed<EOL>buffers = []<EOL>if not statusonly:<EOL><INDENT>try:<EOL><INDENT>matches = self.db.find_records(dict(msg_id={'<STR_LIT>':msg_ids}))<EOL>records = {}<EOL>for rec in matches:<EOL><INDENT>records[rec['<STR_LIT>']] = rec<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>content = error.wrap_exception()<EOL>self.session.send(self.query, "<STR_LIT>", content=content,<EOL>parent=msg, ident=client_id)<EOL>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>records = {}<EOL><DEDENT>for msg_id in msg_ids:<EOL><INDENT>if msg_id in self.pending:<EOL><INDENT>pending.append(msg_id)<EOL><DEDENT>elif msg_id in self.all_completed:<EOL><INDENT>completed.append(msg_id)<EOL>if not statusonly:<EOL><INDENT>c,bufs = self._extract_record(records[msg_id])<EOL>content[msg_id] = c<EOL>buffers.extend(bufs)<EOL><DEDENT><DEDENT>elif msg_id in records:<EOL><INDENT>if rec['<STR_LIT>']:<EOL><INDENT>completed.append(msg_id)<EOL>c,bufs = self._extract_record(records[msg_id])<EOL>content[msg_id] = c<EOL>buffers.extend(bufs)<EOL><DEDENT>else:<EOL><INDENT>pending.append(msg_id)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>raise KeyError('<STR_LIT>'+msg_id)<EOL><DEDENT>except:<EOL><INDENT>content = error.wrap_exception()<EOL><DEDENT>break<EOL><DEDENT><DEDENT>self.session.send(self.query, "<STR_LIT>", content=content,<EOL>parent=msg, ident=client_id,<EOL>buffers=buffers)<EOL>
Get the result of 1 or more messages.