예제 #1
0
    def raw_input(self, prompt=''):
        if self.current_command > len(self.commands) - 1:
            echo('Do you really want to exit ([y]/n)? ', nl=False)
            wait_for(RETURNS)
            self.ask_exit()
            return ''
        # raw_input expects str, but we pass it unicode sometimes
        prompt = py3compat.cast_bytes_py2(prompt)

        try:
            command = self.commands[self.current_command]
            magictype(command, prompt_template=prompt, speed=self.speed)
            line = py3compat.cast_unicode_py2(command)
        except ValueError:
            warn("\n********\nYou or a %run:ed script called sys.stdin.close()"
                 " or sys.stdout.close()!\nExiting IPython!\n")
            self.ask_exit()
            return ""

        # Try to be reasonably smart about not re-indenting pasted input more
        # than necessary.  We do this by trimming out the auto-indent initial
        # spaces, if the user's actual input started itself with whitespace.
        if self.autoindent:
            if num_ini_spaces(line) > self.indent_current_nsp:
                line = line[self.indent_current_nsp:]
                self.indent_current_nsp = 0

        self.current_command += 1
        return line
예제 #2
0
    def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):

        if display_banner is not DISPLAY_BANNER_DEPRECATED:
            warn(
                "interact `display_banner` argument is deprecated since IPython 5.0. "
                "Call `show_banner()` if needed.",
                DeprecationWarning,
                stacklevel=2,
            )  # noqa

        self.keep_running = True
        while self.keep_running:
            print(self.separate_in, end="")

            if self.current_command_index > len(self.commands) - 1:
                echo("Do you really want to exit ([y]/n)? ", nl=False)
                wait_for(RETURNS)
                self.ask_exit()
                return None

            try:
                code = self.prompt_for_code()
            except EOFError:
                if (not self.confirm_exit) or self.ask_yes_no(
                        "Do you really want to exit ([y]/n)?", "y", "n"):
                    self.ask_exit()

            else:
                if code:
                    self.run_cell(code, store_history=True)
예제 #3
0
    def interact(self):
        self.keep_running = True
        while self.keep_running:
            print(self.separate_in, end="")

            if self.current_command_index > len(self.commands) - 1:
                echo("Do you really want to exit ([y]/n)? ", nl=False)
                wait_for(RETURNS)
                self.ask_exit()
                return None

            try:
                code = self.prompt_for_code()
            except EOFError:
                if (not self.confirm_exit) or self.ask_yes_no(
                        "Do you really want to exit ([y]/n)?", "y", "n"):
                    self.ask_exit()

            else:
                if code:
                    self.run_cell(code, store_history=True)