def aggregate(self, messages):
<EOL>if not self.aggregate_count:<EOL><INDENT>return messages<EOL><DEDENT>rv = []<EOL>self.stack = self.stack + messages<EOL>if len(self.stack) < self.aggregate_count:<EOL><INDENT>return rv<EOL><DEDENT>while len(self.stack) >= self.aggregate_count:<EOL><INDENT>message = self.stack[<NUM_LIT:0>]<EOL>self.stack.remove(self.stack[<NUM_LIT:0>])<EOL>for other in self.stack[:self.aggregate_count-<NUM_LIT:1>]:<EOL><INDENT>message["<STR_LIT:data>"].extend(other["<STR_LIT:data>"])<EOL>self.stack.remove(self.stack[<NUM_LIT:0>])<EOL><DEDENT>rv.append(message)<EOL><DEDENT>for message in rv:<EOL><INDENT>self.aggregate_message(message)<EOL><DEDENT>return rv<EOL>
Takes a list of messages and aggregates them
according to aggration config