示例#1
0
 def raw_input(self, *args, **kw):
     try:
         return TerminalInteractiveShell.raw_input(self,
             *args, **kw) # needs decoding (see below)?
     except EOFError:
         r = raw_input("Do you wish to commit your "
                     "database changes? [yes]")
         if not r.lower().startswith("n"):
             if using_sqlalchemy:
                 self.push("session.flush()")
             else:
                 self.push("hub.commit()")
         raise EOFError
示例#2
0
def get_python_console(namespace=None):
    """
    Return a interactive python console instance with caller's stack
    """

    if namespace is None:
        import inspect

        frame = inspect.currentframe()
        caller = frame.f_back
        if not caller:
            logging.error("can't find caller who start this console.")
            caller = frame
        namespace = dict(caller.f_globals)
        namespace.update(caller.f_locals)

    try:
        from IPython.terminal.interactiveshell import TerminalInteractiveShell

        shell = TerminalInteractiveShell(user_ns=namespace)
    except ImportError:
        try:
            import readline
            import rlcompleter

            readline.set_completer(rlcompleter.Completer(namespace).complete)
            readline.parse_and_bind("tab: complete")
        except ImportError:
            pass
        import code

        shell = code.InteractiveConsole(namespace)
        shell._quit = False

        def exit():
            shell._quit = True

        def readfunc(prompt=""):
            if shell._quit:
                raise EOFError
            return six.moves.input(prompt)

        # inject exit method
        shell.ask_exit = exit
        shell.raw_input = readfunc

    return shell
示例#3
0
def get_python_console(namespace=None):
    """
    Return a interactive python console instance with caller's stack
    """

    if namespace is None:
        import inspect
        frame = inspect.currentframe()
        caller = frame.f_back
        if not caller:
            logging.error("can't find caller who start this console.")
            caller = frame
        namespace = dict(caller.f_globals)
        namespace.update(caller.f_locals)

    try:
        from IPython.terminal.interactiveshell import TerminalInteractiveShell
        shell = TerminalInteractiveShell(user_ns=namespace)
    except ImportError:
        try:
            import readline
            import rlcompleter
            readline.set_completer(rlcompleter.Completer(namespace).complete)
            readline.parse_and_bind("tab: complete")
        except ImportError:
            pass
        import code
        shell = code.InteractiveConsole(namespace)
        shell._quit = False

        def exit():
            shell._quit = True

        def readfunc(prompt=""):
            if shell._quit:
                raise EOFError
            return six.moves.input(prompt)

        # inject exit method
        shell.ask_exit = exit
        shell.raw_input = readfunc

    return shell
示例#4
0
 def raw_input(self, prompt=""):
     # TODO correct eof issue with custom prompt.
     prompt = "iridium >>>"
     return TerminalInteractiveShell.raw_input(self, prompt)
示例#5
0
文件: cli.py 项目: subecho/Iridium
 def raw_input(self, prompt=""):
     # TODO correct eof issue with custom prompt.
     prompt = "iridium >>>"
     return TerminalInteractiveShell.raw_input(self, prompt)