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


Python gnureadline.get_begidx方法代码示例

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


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

示例1: complete

# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline 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:reverse-shell,项目名称:routersploit,代码行数:33,代码来源:interpreter.py

示例2: complete

# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline import get_begidx [as 别名]
def complete(self, text, state):
        """Return the next possible completion for 'text'."""
        if state == 0:
            origline = readline.get_line_buffer()
            begidx = readline.get_begidx()
            endidx = readline.get_endidx()
            if begidx > 0:
                cmd, args, foo = self.parseline(origline)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd.lower())
                    except AttributeError:
                        try:
                            compfunc = self.ctx.lookup_compfunction(cmd)
                        except AttributeError:
                            compfunc = self.completedefault
            else:
                compfunc = self.completenames
            arglist = [item.strip() for item in origline.strip().split()]
            comp_state = self.get_compstate(text, arglist)
            self.completion_matches = compfunc(text, origline, arglist, comp_state, begidx, endidx)

        try:
            return self.completion_matches[state]
        except:
            return None

    #def get_names(self):
    #    names = []
    #    classes = [self.__class__]
    #    while classes:
    #        aclass = classes.pop(0)
    #        if aclass.__bases__:
    #            classes = classes + list(aclass.__bases__)
    #        names = names + dir(aclass)
    #    return names 
开发者ID:w3h,项目名称:isf,代码行数:40,代码来源:command.py

示例3: complete

# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline import get_begidx [as 别名]
def complete(self, text, state):
        response = None
        if state == 0:
            # This is the first time for this text,
            # so build a match list.

            origline = readline.get_line_buffer()
            begin = readline.get_begidx()
            end = readline.get_endidx()
            being_completed = origline[begin:end]
            words = origline.split()

            logging.debug('origline=%s', repr(origline))
            logging.debug('begin=%s', begin)
            logging.debug('end=%s', end)
            logging.debug('being_completed=%s', being_completed)
            logging.debug('words=%s', words)

            if not words:
                self.current_candidates = sorted(
                    self.options.keys()
                )
            else:
                try:
                    if begin == 0:
                        # first word
                        candidates = self.options.keys()
                    else:
                        # later word
                        first = words[0]
                        candidates = self.options[first]

                    if being_completed:
                        # match options with portion of input
                        # being completed
                        self.current_candidates = [
                            w for w in candidates
                            if w.startswith(being_completed)
                        ]
                    else:
                        # matching empty string,
                        # use all candidates
                        self.current_candidates = candidates

                    logging.debug('candidates=%s',
                                  self.current_candidates)

                except (KeyError, IndexError) as err:
                    logging.error('completion error: %s', err)
                    self.current_candidates = []

        try:
            response = self.current_candidates[state]
        except IndexError:
            response = None
        logging.debug('complete(%s, %s) => %s',
                      repr(text), state, response)
        return response 
开发者ID:reingart,项目名称:pymotw3,代码行数:60,代码来源:readline_buffer.py


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