当前位置: 首页>>代码示例>>Python>>正文


Python readline.get_completer方法代码示例

本文整理汇总了Python中readline.get_completer方法的典型用法代码示例。如果您正苦于以下问题:Python readline.get_completer方法的具体用法?Python readline.get_completer怎么用?Python readline.get_completer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在readline的用法示例。


在下文中一共展示了readline.get_completer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def run(self, line):
      ishellCompleter = readline.get_completer()
      readline.set_completer_delims(' \t\n;')
      readline.parse_and_bind("tab: complete")
      readline.set_completer(completer.complete)

      sample_file = raw_input('Please enter the filename you want to open: ')
      try:
         sample_fh = open(sample_file,'r')
         feathermodules.samples.extend([sample.strip() for sample in sample_fh.readlines()])
         sample_fh.close()
         feathermodules.samples = filter(lambda x: x != '' and x != None, feathermodules.samples)
      except:
         print 'Something went wrong. Sorry! Please try again.'
      finally:
         readline.set_completer(ishellCompleter) 
开发者ID:nccgroup,项目名称:featherduster,代码行数:18,代码来源:featherduster.py

示例2: do_python

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def do_python(self,arg):
		""" start the local python interpreter (for debugging purposes) """
		orig_exit=builtins.exit
		orig_quit=builtins.quit
		def disabled_exit(*args, **kwargs):
			self.display_warning("exit() disabled ! use ctrl+D to exit the python shell")
		builtins.exit=disabled_exit
		builtins.quit=disabled_exit
		oldcompleter=readline.get_completer()
		try:
			local_ns={"pupsrv":self.pupsrv}
			readline.set_completer(PythonCompleter(local_ns=local_ns).complete)
			readline.parse_and_bind('tab: complete')
			code.interact(local=local_ns)
		except Exception as e:
			self.display_error(str(e))
		finally:
			readline.set_completer(oldcompleter)
			readline.parse_and_bind('tab: complete')
			builtins.exit=orig_exit
			builtins.quit=orig_quit 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:23,代码来源:PupyCmd.py

示例3: _cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def _cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.
        """

        # An almost perfect copy from Cmd; however, the pseudo_raw_input portion
        # has been split out so that it can be called separately

        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    line = self.pseudo_raw_input(self.prompt)
                if (self.echo) and (isinstance(self.stdin, file)):
                    self.stdout.write(line + '\n')
                stop = self.onecmd_plus_hooks(line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass
            return stop 
开发者ID:OpenTrading,项目名称:OpenTrader,代码行数:43,代码来源:cmd2plus.py

示例4: loop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def loop(self):
        previous_completer = readline.get_completer()
        readline.parse_and_bind("tab: complete")
        readline.set_completer(self.walk)
        prompt = self.prompt + self.prompt_delim
        if not ishell._current_prompt:
            previous_prompt = prompt
        else:
            previous_prompt = ishell._current_prompt
        ishell._current_prompt = prompt
        if self.welcome_message:
            sys.stdout.write(self.welcome_message + "\n\r")
        while 1:
            try:
                sys.stdout.write("\r")
                if self._exit:
                    break
                sys.stdout.write("\033[K")
                input_ = input(prompt + " ")
                if not input_.strip():
                    self.print_childs_help()
                elif input_ in ('quit', 'exit'):
                    break
                else:
                    self.walk_and_run(input_)
            except (KeyboardInterrupt, EOFError):
                print("exit")
                break

            except Exception:
                print(traceback.format_exc())
                sys.exit(1)

        ishell._current_prompt = previous_prompt
        readline.set_completer(previous_completer) 
开发者ID:italorossi,项目名称:ishell,代码行数:37,代码来源:console.py

示例5: _cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def _cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.
        """

        # An almost perfect copy from Cmd; however, the pseudo_raw_input portion
        # has been split out so that it can be called separately
        
        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    line = self.pseudo_raw_input(self.prompt)
                if (self.echo) and (isinstance(self.stdin, file)):
                    self.stdout.write(line + '\n')
                stop = self.onecmd_plus_hooks(line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass    
            return stop 
开发者ID:DavexPro,项目名称:PocHunter,代码行数:43,代码来源:cmd2.py

示例6: set_readline

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def set_readline(self):
        if not objectmodel.we_are_translated():
            self.old_completer = readline.get_completer()
            self.old_delims = readline.get_completer_delims()
            readline.set_completer(completer)
            readline.set_completer_delims("\t ") 
开发者ID:hpi-swa,项目名称:RSqueak,代码行数:8,代码来源:shell.py

示例7: cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """

        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    if self.use_rawinput:
                        try:
                            line = raw_input(self.prompt)
                        except EOFError:
                            line = 'EOF'
                    else:
                        self.stdout.write(self.prompt)
                        self.stdout.flush()
                        line = self.stdin.readline()
                        if not len(line):
                            line = 'EOF'
                        else:
                            line = line.rstrip('\r\n')
                line = self.precmd(line)
                stop = self.onecmd(line)
                stop = self.postcmd(stop, line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass 
开发者ID:glmcdona,项目名称:meddle,代码行数:52,代码来源:cmd.py

示例8: isolate_io_context

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def isolate_io_context(function):
    """A decorator for separating I/O context.

    This decorator isolates I/O context of target
    function or method.

    I/O Context is a mix of terminal related elements,
    such as current stdout and readline completer
    attributes.

    This decorator is useful if you run something
    that reconfigures the readline completer, or
    needs to use the default stdout file descriptor
    instead of the phpsploit's stdout wrapper.
    """
    def wrapper(*args, **kwargs):
        try:
            import readline
            handle_readline = True
        except ImportError:
            handle_readline = False

        if handle_readline:
            # backup & reset readline completer
            old_readline_completer = readline.get_completer()
            readline.set_completer((lambda x: x))
            # backup & reset readline history
            old_readline_history = []
            hist_sz = readline.get_current_history_length()
            for i in range(1, hist_sz + 1):
                line = readline.get_history_item(i)
                old_readline_history.append(line)
            readline.clear_history()
        # backup & reset stdout
        old_stdout = sys.stdout
        sys.stdout = sys.__stdout__

        try:
            retval = function(*args, **kwargs)
        finally:

            if handle_readline:
                # restore old readline completer
                readline.set_completer(old_readline_completer)
                # restore old readline history
                readline.clear_history()
                for line in old_readline_history:
                    readline.add_history(line)
            # restore old stdout
            sys.stdout = old_stdout

        return retval
    return wrapper 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:55,代码来源:isolate_io_context.py

示例9: isolate_readline_context

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def isolate_readline_context(function):
    """A decorator for separating readline context.

    This decorator isolates readline context of target
    function or method.

    Use when phpsploit's readline context should be
    reset temporarly is the context of triggering
    function or method.

    Unlike `isolate_io_context`, this decorator keeps
    original stdout wrapper.
    """
    def wrapper(*args, **kwargs):
        try:
            import readline
            handle_readline = True
        except ImportError:
            handle_readline = False

        if handle_readline:
            # backup & reset readline completer
            old_readline_completer = readline.get_completer()
            readline.set_completer((lambda x: x))
            # backup & reset readline history
            old_readline_history = []
            hist_sz = readline.get_current_history_length()
            for i in range(1, hist_sz + 1):
                line = readline.get_history_item(i)
                old_readline_history.append(line)
            readline.clear_history()

        try:
            retval = function(*args, **kwargs)
        finally:

            if handle_readline:
                # restore old readline completer
                readline.set_completer(old_readline_completer)
                # restore old readline history
                readline.clear_history()
                for line in old_readline_history:
                    readline.add_history(line)

        return retval
    return wrapper 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:48,代码来源:isolate_readline_context.py

示例10: cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """
        # try to load readline (if available)
        if self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass

        # print intro message (if any)
        if intro:
            self.intro = intro
        if self.intro:
            self.stdout.write(str(self.intro) + "\n")

        # start command loop
        try:
            self.preloop()  # pre command hook method
            while True:
                try:
                    line = self.raw_input(self.prompt)
                except EOFError:
                    self.stdout.write("\n")
                    line = "exit"
                except BaseException as err:
                    # nothing to interpret on exception
                    self.onexception(err)
                    continue
                try:
                    self.interpret(line, interactive=True)
                # system exit is the correct way to leave loop
                except SystemExit as err:
                    return err.code

        # restore readline completer (if used)
        finally:
            if self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass
            self.postloop()  # post command hook method 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:52,代码来源:shell.py

示例11: imgur

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def imgur(jarvis, s):
    """
    Uploads an image to imgur
    """

    # Autocomplete filename
    jarvis.say("What's the image name?: ")
    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete")
    r = readline.get_completer()
    readline.set_completer(complete)
    file = jarvis.input('')
    # Get the absolute path
    file = os.path.abspath(file)
    file = os.path.expanduser(file)
    if os.path.isfile(file):
        try:
            url = "https://api.imgur.com/3/image"
            headers = {"Authorization": "Client-ID 145b6ea95cf11b4"}
            # Send POST
            resp = requests.post(
                url,
                headers=headers,
                data={
                    'image': base64.b64encode(open(file, 'rb').read()),
                    'type': 'base64'
                }
            )

            objresp = json.loads(resp.text)
            # Treat response
            if objresp.get('success', False):
                jarvis.say('Here is your image: '
                           + str(objresp['data']['link']))
            else:
                jarvis.say('Error: ' + str(objresp['data']['error']))
        except Exception as e:
            # Print exception as string
            jarvis.say("Error {0}".format(str(e.args[0])).encode("utf-8"))
    else:
        jarvis.say("No such file")

    readline.set_completer(r) 
开发者ID:sukeesh,项目名称:Jarvis,代码行数:45,代码来源:imgur.py

示例12: cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """

        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    self.preinput()
                    if self.use_rawinput:
                        try:
                            line = input(self.prompt)
                        except EOFError:
                            line = 'EOF'
                    else:
                        self.stdout.write(self.prompt)
                        self.stdout.flush()
                        line = self.stdin.readline()
                        if not len(line):
                            line = 'EOF'
                        else:
                            line = line[:-1]  # chop \n
                    line = self.postinput(line)
                line = self.precmd(line)
                stop = self.onecmd(line)
                stop = self.postcmd(stop, line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass 
开发者ID:zhuyifei1999,项目名称:guppy3,代码行数:54,代码来源:cmd.py

示例13: cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """

        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    if self.use_rawinput:
                        try:
                            line = input(self.prompt)
                        except EOFError:
                            line = 'EOF'
                    else:
                        self.stdout.write(self.prompt)
                        self.stdout.flush()
                        line = self.stdin.readline()
                        if not len(line):
                            line = 'EOF'
                        else:
                            line = line.rstrip('\r\n')
                line = self.precmd(line)
                stop = self.onecmd(line)
                stop = self.postcmd(stop, line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:52,代码来源:cmd.py

示例14: cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        """
        # Custom change: added hadling for ctrl+c
        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                import readline
                self.old_completer = readline.get_completer()
                readline.set_completer(self.complete)
                readline.parse_and_bind(self.completekey+": complete")
            except ImportError:
                pass
        try:
            if intro is not None:
                self.intro = intro
            if self.intro:
                self.stdout.write(str(self.intro)+"\n")
            stop = None
            while not stop:
                try:
                    if self.cmdqueue:
                        line = self.cmdqueue.pop(0)
                    else:
                        if self.use_rawinput:
                            try:
                                line = raw_input(self.prompt)
                            except EOFError:
                                line = 'EOF'
                        else:
                            self.stdout.write(self.prompt)
                            self.stdout.flush()
                            line = self.stdin.readline()
                            if not len(line):
                                line = 'EOF'
                            else:
                                line = line.rstrip('\r\n')
                    line = self.precmd(line)
                    stop = self.onecmd(line)
                    stop = self.postcmd(stop, line)
                except KeyboardInterrupt:
                    print("^C")
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    import readline
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass 
开发者ID:antonioCoco,项目名称:SharPyShell,代码行数:55,代码来源:SharPyShellPrompt.py

示例15: run_interactive_gtp_session

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_completer [as 别名]
def run_interactive_gtp_session(engine):
    """Run a GTP engine session on stdin and stdout, using readline.

    engine -- Gtp_engine_protocol object

    This enables readline tab-expansion, and command history in
    ~/.gomill-gtp-history (if readline is available).

    Returns either when EOF is seen on stdin, or when the engine signals end of
    session.

    If stdin isn't a terminal, this is equivalent to run_gtp_session.

    If a write fails with 'broken pipe', this raises ControllerDisconnected.

    Note that this will propagate KeyboardInterrupt if the user presses ^C;
    normally you'll want to handle this to avoid an ugly traceback.

    """
    # readline doesn't do anything if stdin isn't a tty, but it's simplest to
    # just not import it in that case.
    try:
        use_readline = os.isatty(sys.stdin.fileno())
        if use_readline:
            import readline
    except Exception:
        use_readline = False
    if not use_readline:
        run_gtp_session(engine, sys.stdin, sys.stdout)
        return

    def write(s):
        sys.stdout.write(s)
        sys.stdout.flush()

    history_pathname = os.path.expanduser("~/.gomill-gtp-history")
    readline.parse_and_bind("tab: complete")
    old_completer = readline.get_completer()
    old_delims = readline.get_completer_delims()
    readline.set_completer(make_readline_completer(engine))
    readline.set_completer_delims("")
    try:
        readline.read_history_file(history_pathname)
    except EnvironmentError:
        pass
    _run_gtp_session(engine, raw_input, write)
    try:
        readline.write_history_file(history_pathname)
    except EnvironmentError:
        pass
    readline.set_completer(old_completer)
    readline.set_completer_delims(old_delims) 
开发者ID:pnprog,项目名称:goreviewpartner,代码行数:54,代码来源:gtp_engine.py


注:本文中的readline.get_completer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。