當前位置: 首頁>>代碼示例>>Python>>正文


Python readline.set_completer方法代碼示例

本文整理匯總了Python中readline.set_completer方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.set_completer方法的具體用法?Python readline.set_completer怎麽用?Python readline.set_completer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在readline的用法示例。


在下文中一共展示了readline.set_completer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_console

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [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: __init__

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [as 別名]
def __init__(self):
        """Create the main mode.

        If titus.inspector.defs.CONFIG_DIRECTORY_EXISTS is ``True``, get the readline history file from the user's titus.inspector.defs.CONFIG_DIRECTORY.
        """

        if CONFIG_DIRECTORY_EXISTS:
            self.historyPath = os.path.join(os.path.expanduser(CONFIG_DIRECTORY), self.historyFileName)
            if not os.path.exists(self.historyPath):
                open(self.historyPath, "w").close()

            self.active = True
            self.tabCompleter = TabCompleter(self)
            readline.read_history_file(self.historyPath)
            readline.set_completer(self.tabCompleter.complete)

            def writehistory():
                if self.active:
                    readline.write_history_file(self.historyPath)
            atexit.register(writehistory) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:22,代碼來源:defs.py

示例3: get_input_autocomplete

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [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

示例4: show_menu

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [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

示例5: run

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_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

示例6: setup

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [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 set_completer [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 set_completer [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 set_completer [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 set_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

示例11: get_command

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [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 set_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

示例13: pause

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [as 別名]
def pause(self):
        """Write the current history to the history file and stop readline."""
        readline.write_history_file(self.historyPath)
        readline.clear_history()
        readline.set_completer()
        self.active = False 
開發者ID:modelop,項目名稱:hadrian,代碼行數:8,代碼來源:defs.py

示例14: resume

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_completer [as 別名]
def resume(self):
        """Read the history file and restart readline."""
        self.active = True
        readline.read_history_file(self.historyPath)
        readline.set_completer(self.tabCompleter.complete) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:7,代碼來源:defs.py

示例15: loop

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_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


注:本文中的readline.set_completer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。