For example, the built-in python suite processes uses this function to collect a multiline python suite before executing it.
427: #line 673 "input_frame.ipk" 428: def collect_stuff(self,prefix, cont_re, echo): 429: saved = prefix 430: try: 431: file2,count2,line = self.readline() 432: match = cont_re.match(line) 433: while match: 434: if echo: 435: print '%s %6s: %s' % (file2,count2,line) 436: body = match.group(1) 437: if not body: body = '' 438: saved = saved+'\n'+body 439: file2,count2,line = self.readline() 440: match = cont_re.match(line) 441: self.enqueue_input(file2,count2,line) 442: except eoi: 443: pass 444: saved = saved + '\n' 445: return saved 446: 447: def collect_lines_upto(self,terminal): 448: term_re = re.compile('^'+terminal+'$') 449: saved = [] 450: file,count,line = self.readline() 451: match = term_re.match(line) 452: while not match: 453: saved.append(line) 454: file,count,line = self.readline() 455: match = term_re.match(line) 456: return saved 457: 458: def collect_upto(self,terminal): 459: return string.join(self.collect_lines_upto(terminal), '\n')+'\n' 460: 461: def python(self, terminal='@end_python'): 462: file = self.original_filename 463: count = self.original_count 464: glb = self.global_frame.__dict__ 465: user = self.userdict 466: data = self.collect_upto(terminal) 467: self.process.py_exec(data,file,count,glb,user) 468:
6.10.10.2.14.1. Test python function
6.10.10.2.14.2. Print diff table