66 def eval(self, console):
67 console.write ('\n')
68 orig_stdout = sys.stdout
69 sys.stdout = IPython.Shell.Term.cout
70 try:
71 line = self.IP.raw_input(None, self.iter_more)
72 if self.IP.autoindent:
73 self.IP.readline_startup_hook(None)
74 except KeyboardInterrupt:
75 self.IP.write('\nKeyboardInterrupt\n')
76 self.IP.resetbuffer()
77 self.IP.outputcache.prompt_count -= 1
78 if self.IP.autoindent:
79 self.IP.indent_current_nsp = 0
80 self.iter_more = 0
81 except:
82 self.IP.showtraceback()
83 else:
84 self.iter_more = self.IP.push(line)
85 if (self.IP.SyntaxTB.last_syntax_error and self.IP.rc.autoedit_syntax):
86 self.IP.edit_syntax_error()
87 if self.iter_more:
88 self.prompt = str(self.IP.outputcache.prompt2).strip()
89 if self.IP.autoindent:
90 self.IP.readline_startup_hook(self.IP.pre_readline)
91 else:
92 self.prompt = str(self.IP.outputcache.prompt1).strip()
93 sys.stdout = orig_stdout
94
95
96 while True:
97 try:
98 buf = os.read(console.piperead, 256)
99 except:
100 break
101 else:
102 console.write (buf)
103 if len(buf) < 256: break
104
105
106 rv = console.cout.getvalue()
107 if rv:
108 rv = rv.strip('\n')
109 console.write (rv)
110 if rv:
111 console.write ('\n')
112 console.cout.truncate(0)
113 console.prompt()
114