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


Python gnureadline.get_line_buffer方法代碼示例

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


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

示例1: complete

# 需要導入模塊: import gnureadline [as 別名]
# 或者: from gnureadline import get_line_buffer [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_line_buffer [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_line_buffer [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_line_buffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。