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


Python readline.get_begidx方法代码示例

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


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

示例1: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """:type text: string
        :param text: partial text to complete
        :type state: integer
        :param state: the number of times the user has pressed tab. If ``0``, generate a new list of candidates; otherwise, use the old one
        :rtype: list of strings
        :return: set of completions
        """

        if state == 0:
            line = readline.get_line_buffer()
            begin = readline.get_begidx()
            end = readline.get_endidx()
            established = line[:begin]
            active = line[begin:end]
            self.candidates = self.mode.complete(established, active)
        try:
            return self.candidates[state]
        except IndexError:
            return None 
开发者ID:modelop,项目名称:hadrian,代码行数:22,代码来源:defs.py

示例2: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        try:
            if state >= 0:
                origline = readline.get_line_buffer()
                line = origline.lstrip()
                stripped = len(origline) - len(line)
                begidx = readline.get_begidx() - stripped
                endidx = readline.get_endidx() - stripped
                compfunc = self.completenames
                self.completion_matches = compfunc(text, line, begidx, endidx)
        except Exception:
            pass

        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:aerospike,项目名称:aerospike-admin,代码行数:24,代码来源:asadm.py

示例3: complete_control_command

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete_control_command(line: str, text: str) -> List[str]:
    from polysh import control_commands
    if readline.get_begidx() == 0:
        # Completing control command name
        cmds = list_control_commands()
        prefix = text[1:]
        matches = [':' + cmd + ' ' for cmd in cmds if cmd.startswith(prefix)]
    else:
        # Completing control command parameters
        cmd = line.split()[0][1:]

        def def_compl(line: str) -> List:
            return []
        compl_func = getattr(control_commands, 'complete_' + cmd, def_compl)
        matches = compl_func(line, text)
    return matches 
开发者ID:innogames,项目名称:polysh,代码行数:18,代码来源:control_commands_helpers.py

示例4: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:glmcdona,项目名称:meddle,代码行数:31,代码来源:cmd.py

示例5: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped

            # get the current command's name (argv[0])
            try:
                name = self.parseline(line)[-1][0]
            except:
                name = None
            # if the cmd name has been entirely typed, then use it's dedicated
            # complete_*() method, or fallback to completedefault().
            if begidx > 0:
                try:
                    compfunc = getattr(self, 'complete_'+name)
                except AttributeError:
                    compfunc = self.completedefault
            # if the cmd name is being typed, completion must suggest the
            # available commands list, aka completenames()
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state] + ' '
        except IndexError:
            return None 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:37,代码来源:shell.py

示例6: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            original_line = readline.get_line_buffer()
            line = original_line.lstrip()
            stripped = len(original_line) - len(line)
            start_index = readline.get_begidx() - stripped
            end_index = readline.get_endidx() - stripped

            if start_index > 0:
                cmd, args = self.parse_line(line)
                if cmd == '':
                    complete_function = self.default_completer
                else:
                    try:
                        complete_function = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        complete_function = self.default_completer
            else:
                complete_function = self.raw_command_completer
        self.completion_matches = complete_function(text, line, start_index, end_index)

        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:d0ubl3g,项目名称:Industrial-Security-Auditing-Framework,代码行数:32,代码来源:BaseInterpreter.py

示例7: _complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def _complete(self, text: str, state: int) -> Optional[Sequence[str]]:
        """ Return the next possible completion for `text`.

        If a command has not been entered, then complete against command list.
        Otherwise try to call specific command completer function to get list
        of completions.
        """
        if state == 0:
            original_line = readline.get_line_buffer()
            line = original_line.lstrip()
            stripped = len(original_line) - len(line)
            start_index = readline.get_begidx() - stripped
            end_index = readline.get_endidx() - stripped

            if start_index > 0 and line:
                cmd, *_ = self._parse_line(line)
                try:
                    complete_function = self._get_command(cmd).complete
                except CommandError:
                    return
            else:
                complete_function = self._raw_command_completer

            self.completion_matches = complete_function(
                text, line, start_index, end_index
            )

        try:
            return self.completion_matches[state]
        except IndexError:
            return 
开发者ID:fwkz,项目名称:riposte,代码行数:33,代码来源:riposte.py

示例8: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:zhuyifei1999,项目名称:guppy3,代码行数:31,代码来源:cmd.py

示例9: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
		if state == 0:
			import readline
			origline = readline.get_line_buffer()
			line = origline.lstrip()
			stripped = len(origline) - len(line)
			begidx = readline.get_begidx() - stripped
			endidx = readline.get_endidx() - stripped
			if begidx>0:
				cmd, args, foo = self.parseline(line)
				if cmd == '':
					compfunc = self.completedefault
				else:
					try:
						#compfunc = getattr(self, 'complete_' + cmd)
						compfunc = self.pupy_completer.complete
					except AttributeError:
						compfunc = self.completedefault
			else:
				compfunc = self.completenames
			self.completion_matches = compfunc(text, line, begidx, endidx)
		try:
			return self.completion_matches[state]
		except IndexError:
			return None

	#text : word match
	#line : complete line 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:30,代码来源:PupyCmd.py

示例10: filepaths

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def filepaths(text):
    import readline
    everything = readline.get_line_buffer()
    cursor_idx = readline.get_begidx()
    idx = 0
    for chunk in everything.split(" "):
        fullpath = chunk
        idx += len(chunk) + 1
        if idx > cursor_idx:
            break

    if os.path.isfile(fullpath):
        return None
    if "/" in fullpath:
        d = os.path.dirname(fullpath)
    else:
        d = "."

    res = []
    for candidate in os.listdir(d):
        if not candidate.startswith(text):
            continue
        if os.path.isdir(d+os.path.sep+candidate):
            res.append(candidate + os.path.sep)
        else:
            res.append(candidate + " ")
    return res 
开发者ID:zerosum0x0,项目名称:koadic,代码行数:29,代码来源:spool.py

示例11: autocomplete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def autocomplete(shell, line, text, state):
    import readline
    everything = readline.get_line_buffer()
    cursor_idx = readline.get_begidx()
    idx = 0
    for chunk in everything.split(" "):
        fulltext = chunk
        idx += len(chunk) + 1
        if idx > cursor_idx:
            break
    prefix, suffix = fulltext.rsplit("/",maxsplit=1) if "/" in fulltext else ("",fulltext)
    if prefix:
        prefix += "/"

    options = []
    tmp = list(shell.plugins.keys())
    for plugin in shell.plugins:
        tmp.append(plugin.split("/")[-1])
    for plugin in tmp:
        if not plugin.startswith(fulltext):
            continue
        chunk = plugin[len(prefix):]
        if "/" in chunk:
            options.append(chunk.split("/")[0]+"/")
        else:
            options.append(chunk+" ")
    options = list(sorted(set(options)))
    try:
        return options[state]
    except:
        return None 
开发者ID:zerosum0x0,项目名称:koadic,代码行数:33,代码来源:use.py

示例12: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, token, state):
        """Return a possible completion for readline

        This function is called with state starting at zero to get the
        first completion, then one/two/three etc until you return None.  The best
        implementation is to generate the list when state==0, save it,
        and provide members on each increase.

        The default implementation extracts the current full input
        from readline and then calls :meth:`complete_command` or
        :meth:`complete_sql` as appropriate saving the results for
        subsequent calls.
        """
        if state==0:
            import readline
            # the whole line
            line=readline.get_line_buffer()
            # beginning and end(+1) of the token in line
            beg=readline.get_begidx()
            end=readline.get_endidx()
            # Are we matching a command?
            try:
                if self._completion_first and line.startswith("."):
                    self.completions=self.complete_command(line, token, beg, end)
                else:
                    self.completions=self.complete_sql(line, token, beg, end)
            except:
                # Readline swallows any exceptions we raise.  We
                # shouldn't be raising any so this is to catch that
                import traceback; traceback.print_exc()
                raise

        if state>len(self.completions):
            return None
        return self.completions[state]

    # Taken from https://sqlite.org/lang_keywords.html 
开发者ID:plasticityai,项目名称:magnitude,代码行数:39,代码来源:shell.py

示例13: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            old_delims = readline.get_completer_delims()
            readline.set_completer_delims(old_delims.replace('#', ''))
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:antonioCoco,项目名称:SharPyShell,代码行数:33,代码来源:SharPyShellPrompt.py

示例14: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """
        auto-complete selection based on given text and state parameters
        """
        if state == 0:
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                mod, args, foo = self.parseline(line)
                if mod == '':
                    return self.complete_modules(text)[state]
                elif not mod in self.modules:
                    logger.error("BUG: mod '{}' not found!".format(mod))
                else:
                    module = self.modules[mod]
                    self.completion_matches = \
                        self.complete_functions(module, text, line, begidx, endidx)
            else:
                self.completion_matches = self.complete_modules(text)
        try:
            return self.completion_matches[state]
        except IndexError:
            return ['']

    # Execute commands from Modules 
开发者ID:OpenSIPS,项目名称:opensips-cli,代码行数:30,代码来源:cli.py

示例15: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            origline = readline.get_line_buffer()

            # Offer completion just for commands that starts
            # with the trigger :
            if origline and not origline.startswith(':'):
                return None

            line = origline.lstrip().lstrip(':')

            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            if self.completion_matches[state].startswith('alias_'):
                if self.session.get('default_shell') == 'shell_php':
                    return self.completion_matches[state][6:]
                else:
                    return ''
            else:
                return self.completion_matches[state]
        except IndexError:
            return None 
开发者ID:epinna,项目名称:weevely3,代码行数:43,代码来源:terminal.py


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