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


Python readline.parse_and_bind方法代码示例

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


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

示例1: run_console

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def run_console(glob):
    import readline
    import rlcompleter
    import atexit
    import code

    history_path = os.path.expanduser("~/.python_history")

    def save_history(history_path=history_path):
        readline.write_history_file(history_path)
    if os.path.exists(history_path):
        readline.read_history_file(history_path)

    atexit.register(save_history)

    readline.set_completer(rlcompleter.Completer(glob).complete)
    readline.parse_and_bind("tab: complete")
    code.InteractiveConsole(locals=glob).interact() 
开发者ID:Deepwalker,项目名称:pundler,代码行数:20,代码来源:pundle.py

示例2: get_input_autocomplete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def get_input_autocomplete(message=''):
    """ Allow user to type input and provide auto-completion """

    # Apple does not ship GNU readline with OS X.
    # It does ship BSD libedit which includes a readline compatibility interface.
    # Source: https://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
    readline.set_completer(autocomplete)

    try:
        return input(message).strip()
    except KeyboardInterrupt:
        return False
    except Exception:  # Other Exception
        return False 
开发者ID:gabfl,项目名称:vault,代码行数:20,代码来源:autocomplete.py

示例3: show_menu

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def show_menu(CommandClass, CompleterClass, name):
    command = CommandClass(name)
    completer = CompleterClass(command)
    readline.set_completer(completer.complete)
    readline.set_completer_delims(" ")
    readline.parse_and_bind("tab: complete")

    res = False
    while res is not True:
        valid_commands = command.cmd.keys()

        ret_cmd = six.input("%s> " % name).strip()
        cmd, options = (ret_cmd.split(" ")[0], " ".join(ret_cmd.split(" ")[1:]))
        if cmd == "debug":
            pdb.set_trace()

        elif cmd.lower() in valid_commands:
            res = command.run_cmd(cmd, options)

        else:
            print("Invalid command.")

        readline.set_completer(completer.complete) 
开发者ID:depthsecurity,项目名称:armory,代码行数:25,代码来源:armory_interactive.py

示例4: run

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [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

示例5: configureCompletion

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def configureCompletion(self) -> None:
        try:
            from jedi.utils import setup_readline
            setup_readline()
        except ImportError:
            # Fallback to the stdlib readline completer if it is installed.
            # Taken from http://docs.python.org/2/library/rlcompleter.html
            runtime.ui.info("jedi is not installed, falling back to readline"
                " for completion")
            try:
                import readline
                import rlcompleter
                readline.parse_and_bind("tab: complete")
            except ImportError:
                runtime.ui.info("readline is not installed either."
                    " No tab completion is enabled.") 
开发者ID:OfflineIMAP,项目名称:imapfw,代码行数:18,代码来源:shell.py

示例6: setup

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def setup(self):
        """ Initialization of third-party libraries

        Setting interpreter history.
        Setting appropriate completer function.

        :return:
        """
        if not os.path.exists(self.history_file):
            open(self.history_file, 'a+').close()

        readline.read_history_file(self.history_file)
        readline.set_history_length(self.history_length)
        atexit.register(readline.write_history_file, self.history_file)

        readline.parse_and_bind('set enable-keypad on')

        readline.set_completer(self.complete)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete") 
开发者ID:d0ubl3g,项目名称:Industrial-Security-Auditing-Framework,代码行数:22,代码来源:BaseInterpreter.py

示例7: Input_completer

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def Input_completer(keywords):
    completer = MyCompleter(keywords)
    readline.set_completer(completer.complete)
    if "libedit" in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind('tab: complete')
        #readline.parse_and_bind('"\\e[A": complete') # Up arrow
    readline.parse_and_bind("set colored-completion-prefix on")
    readline.parse_and_bind("set show-all-if-unmodified on")
    readline.parse_and_bind("set horizontal-scroll-mode on")
    if os.path.exists(history_file):
        readline.read_history_file(history_file)
        readline.set_history_length(20)
    readline.set_completer_delims(' ')
    atexit.register(save_history) 
开发者ID:OWASP,项目名称:QRLJacking,代码行数:18,代码来源:utils.py

示例8: use

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def use(self,args,pointer = None):
		global POINTER
		if(len(args) < 2):
			return None
		POINTER = args[1]
		moduleName = args[1].split('/')
		comp 	= Completer()
		readline.set_completer_delims(' \t\n;')
		readline.parse_and_bind("tab: complete")
		readline.set_completer(comp.complete)
		while True:
			input	= raw_input('SMOD ' + moduleName[0] + '(' + bcolors.OKBLUE + moduleName[-1] + bcolors.ENDC + ') >').strip().split()
			try:			
				result 	= getattr(globals()['Command'](),input[0])(input,args[1])
			except:
				return None
			if (POINTER == None):
				break 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:20,代码来源:Interface.py

示例9: init_readline

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def init_readline(complete_method, histfile=None):
    """init the readline library if available"""
    try:
        import readline
        readline.parse_and_bind("tab: complete")
        readline.set_completer(complete_method)
        string = readline.get_completer_delims().replace(':', '')
        readline.set_completer_delims(string)
        if histfile is not None:
            try:
                readline.read_history_file(histfile)
            except IOError:
                pass
            import atexit
            atexit.register(readline.write_history_file, histfile)
    except:
        print('readline si not available :-(') 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:19,代码来源:cli.py

示例10: do_python

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [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

示例11: get_command

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def get_command(self, prompt, auto_complete_fn=None, basefile_fn=None):
        try:
            if auto_complete_fn != None:
                import readline
                readline.set_completer_delims(' \t\n;/')
                readline.parse_and_bind("tab: complete")
                readline.set_completer(auto_complete_fn)
                # readline.set_completion_display_matches_hook(basefile_fn)
        except:
            pass

        # python3 changes raw input name
        if sys.version_info[0] == 3:
            raw_input = input
        else:
            raw_input = __builtins__['raw_input']

        cmd = raw_input("%s" % prompt)
        return cmd.strip() 
开发者ID:zerosum0x0,项目名称:koadic,代码行数:21,代码来源:shell.py

示例12: _cmdloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [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

示例13: loop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [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

示例14: completer

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def completer():
    # source: https://gist.github.com/iamatypeofwalrus/5637895
    class tabCompleter(object):
        def pathCompleter(self,text,state):
            line   = readline.get_line_buffer().split()
            return [x for x in glob(text+'*')][state]
        def createListCompleter(self,ll):
            pass
            def listCompleter(text,state):
                line   = readline.get_line_buffer()
                if not line:
                    return None
                else:
                    return [c + " " for c in ll if c.startswith(line)][state]
            self.listCompleter = listCompleter
    t = tabCompleter()
                            # tool command
    t.createListCompleter(["clear", "exit", "banner","exec","restart", "upgrade", 'search'
                            # modules
                            # auxiliary modules
                             ,"use auxiliary/gather/ip_gather","use auxiliary/gather/ip_lookup", "use auxiliary/core/pyconverter"
                            # exploit modules
                             ,"use exploit/windows/ftp/ftpshell_overflow", "use exploit/android/login/login_bypass", "use exploit/windows/http/oracle9i_xdb_pass"])
    readline.set_completer_delims('\t')
    readline.parse_and_bind("tab: complete")
    readline.set_completer(t.listCompleter) 
开发者ID:ahmadnourallah,项目名称:pysploit-framework,代码行数:28,代码来源:main_completer.py

示例15: setupReadline

# 需要导入模块: import readline [as 别名]
# 或者: from readline import parse_and_bind [as 别名]
def setupReadline(local):
    """Initialize the readline library and command history.

    @return: A C{bool} to indicate whether standard input is a terminal
        (and therefore interactive).
    """
    readline.parse_and_bind('tab: complete')
    readline.set_completer_delims(' \t\n')
    readline.set_completer(Completer(local).complete)

    # Readline code from https://docs.python.org/3.7/library/readline.html
    histfile = os.path.join(os.path.expanduser('~'), '.daudin_history')

    try:
        readline.read_history_file(histfile)
        historyLen = readline.get_current_history_length()
    except FileNotFoundError:
        open(histfile, 'wb').close()
        historyLen = 0

    try:
        readline.append_history_file
    except AttributeError:
        # We won't be able to save readline history. This can happen on
        # Python 3.5 at least - not sure why.
        pass
    else:
        import atexit

        def saveHistory(prevHistoryLen, histfile):
            newHistoryLen = readline.get_current_history_length()
            readline.set_history_length(1000)
            readline.append_history_file(newHistoryLen - prevHistoryLen,
                                         histfile)

        atexit.register(saveHistory, historyLen, histfile)

    return True 
开发者ID:terrycojones,项目名称:daudin,代码行数:40,代码来源:readline.py


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