Esempio n. 1
0
 def push(self, line):
     """Push a line to the interpreter."""
     self._buffer.append(line)
     source = "\n".join(self._buffer)
     self.write(line + "\n")
     # We do two special things with the context managers here:
     #   - We replace stdout/stderr to capture output. Even if we could
     #     override InteractiveInterpreter's write method, most things are
     #     printed elsewhere (e.g. by exec). Other Python GUI shells do the
     #     same.
     #   - We disable our exception hook, so exceptions from the console get
     #     printed and don't open a crashdialog.
     with utils.fake_io(self.write), utils.disabled_excepthook():
         self._more = self._interpreter.runsource(source, "<console>")
     self.write(self._curprompt())
     if not self._more:
         self._buffer = []
Esempio n. 2
0
 def push(self, line):
     """Push a line to the interpreter."""
     self._buffer.append(line)
     source = '\n'.join(self._buffer)
     self.write(line + '\n')
     # We do two special things with the context managers here:
     #   - We replace stdout/stderr to capture output. Even if we could
     #     override InteractiveInterpreter's write method, most things are
     #     printed elsewhere (e.g. by exec). Other Python GUI shells do the
     #     same.
     #   - We disable our exception hook, so exceptions from the console get
     #     printed and don't open a crashdialog.
     with utils.fake_io(self.write), utils.disabled_excepthook():
         self._more = self._interpreter.runsource(source, '<console>')
     self.write(self._curprompt())
     if not self._more:
         self._buffer = []