For example, the built-in python suite processes uses this function to collect a multiline python suite before executing it.
549: #line 805 "input_frame.ipk" 550: def collect_stuff(self,prefix, cont_re, echo): 551: saved = prefix 552: try: 553: file2,count2,line = self.readline() 554: match = cont_re.match(line) 555: while match: 556: if echo: 557: print '%s %6s: %s' % (file2,count2,line) 558: body = match.group(1) 559: if not body: body = '' 560: saved = saved+'\n'+body 561: file2,count2,line = self.readline() 562: match = cont_re.match(line) 563: self.enqueue_input(file2,count2,line) 564: except eoi: 565: pass 566: saved = saved + '\n' 567: return saved 568: 569: def collect_lines_upto(self,terminal): 570: term_re = re.compile('^'+terminal+'$') 571: saved = [] 572: file,count,line = self.readline() 573: match = term_re.match(line) 574: while not match: 575: saved.append(line) 576: file,count,line = self.readline() 577: match = term_re.match(line) 578: return saved 579: 580: def collect_upto(self,terminal): 581: return string.join(self.collect_lines_upto(terminal), '\n')+'\n' 582: