def interact(self, display_banner=None):
<EOL>if self.exit_now:<EOL><INDENT>return<EOL><DEDENT>if display_banner is None:<EOL><INDENT>display_banner = self.display_banner<EOL><DEDENT>if isinstance(display_banner, str):<EOL><INDENT>self.show_banner(display_banner)<EOL><DEDENT>elif display_banner:<EOL><INDENT>self.show_banner()<EOL><DEDENT>more = False<EOL>if self.has_readline:<EOL><INDENT>self.readline_startup_hook(self.pre_readline)<EOL>hlen_b4_cell = self.readline.get_current_history_length()<EOL><DEDENT>else:<EOL><INDENT>hlen_b4_cell = <NUM_LIT:0><EOL><DEDENT>while not self.exit_now:<EOL><INDENT>self.hooks.pre_prompt_hook()<EOL>if more:<EOL><INDENT>try:<EOL><INDENT>prompt = self.prompt_manager.render('<STR_LIT>')<EOL><DEDENT>except:<EOL><INDENT>self.showtraceback()<EOL><DEDENT>if self.autoindent:<EOL><INDENT>self.rl_do_indent = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>prompt = self.separate_in + self.prompt_manager.render('<STR_LIT>')<EOL><DEDENT>except:<EOL><INDENT>self.showtraceback()<EOL><DEDENT><DEDENT>try:<EOL><INDENT>line = self.raw_input(prompt)<EOL>if self.exit_now:<EOL><INDENT>break<EOL><DEDENT>if self.autoindent:<EOL><INDENT>self.rl_do_indent = False<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>try:<EOL><INDENT>self.write('<STR_LIT>')<EOL>source_raw = self.input_splitter.source_raw_reset()[<NUM_LIT:1>]<EOL>hlen_b4_cell =self._replace_rlhist_multiline(source_raw, hlen_b4_cell)<EOL>more = False<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except EOFError:<EOL><INDENT>if self.autoindent:<EOL><INDENT>self.rl_do_indent = False<EOL>if self.has_readline:<EOL><INDENT>self.readline_startup_hook(None)<EOL><DEDENT><DEDENT>self.write('<STR_LIT:\n>')<EOL>self.exit()<EOL><DEDENT>except bdb.BdbQuit:<EOL><INDENT>warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>except:<EOL><INDENT>self.showtraceback()<EOL><DEDENT>else:<EOL><INDENT>self.input_splitter.push(line)<EOL>more = self.input_splitter.push_accepts_more()<EOL>if (self.SyntaxTB.last_syntax_error and<EOL>self.autoedit_syntax):<EOL><INDENT>self.edit_syntax_error()<EOL><DEDENT>if not more:<EOL><INDENT>source_raw = self.input_splitter.source_raw_reset()[<NUM_LIT:1>]<EOL>self.run_cell(source_raw, store_history=True)<EOL>hlen_b4_cell =self._replace_rlhist_multiline(source_raw, hlen_b4_cell)<EOL><DEDENT><DEDENT><DEDENT>self.exit_now = False<EOL>
Closely emulate the interactive Python console.