• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python readline.get_endidx函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: complete

    def complete(self, text, state):
        response = None
        if state == 0:
            # 首次输入文本,建立匹配项
            origline = readline.get_line_buffer()
            begin = readline.get_begidx()
            end = readline.get_endidx()
            being_completed = origline[begin:end]
            words = origline.split()

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

                    if being_completed:
                        self.current_candidates = [
                            w for w in candidates
                            if w.startswith(being_completed)
                        ]
                    else:
                        self.current_candidates = candidates
                except (KeyError, IndexError), err:
                    self.current_candidates = []

            try:
                response = self.current_candidates[state]
            except IndexError:
                response = None
            return response
开发者ID:coldnight,项目名称:pyscripts,代码行数:35,代码来源:readline_buffer.py


示例2: complete

def complete(text, state):
    """Tab complete for readline."""

    line = readline.get_line_buffer()
    
    # there is a difference in the way line buffer is handled by GNU readline
    # and by libedit, which is what runs by default on OSX. With GNU readline
    # the line buffer is empty after each command; with libedit, old buffer
    # remains, and gets overwritten from the beginning on (if the previous
    # line was 'foobaz', and someone types 'xxx' on new line, then the line
    # buffer is 'xxxbaz'). This is why the content of the line buffer needs to
    # be trimmed, if completion decisions are to be made based on the buffer
    # content. 
    #
    line = line[:readline.get_endidx()]

    # first token
    if text == line:
        matches = [c+" " for c in completions['commands'] if 
            c.startswith(text.lower())]
    
    else:
        command = line.split(" ")[0].lower()
        if command in ['view', 'open']:
            matches = [h['_id'] for 
                h in completions['hits'] if 
                h['_id'].startswith(text)]
        elif command in ['count', 'search']: 
            matches = [f for 
                f in completions['fields'] if 
                f.startswith(text)]

    response = sorted(matches)[state]
    return response
开发者ID:mkocikowski,项目名称:elsec,代码行数:34,代码来源:parser.py


示例3: get_endidx

 def get_endidx ( self ):
     if util.isPlatformWindows ():
         import pyreadline
         return Readline ().get_endidx ()
     else:
         import readline
         return readline.get_endidx ()
开发者ID:Juniper,项目名称:OpenClos,代码行数:7,代码来源:cli.py


示例4: complete

    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:nattee,项目名称:cafe-grader-web,代码行数:30,代码来源:cmd.py


示例5: complete

    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()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped

            wordCnt = len(line[:begidx].split())

            if wordCnt <= 0:
                self.completion_matches = self.completenames(text, line, begidx, endidx)
            elif wordCnt == 1:
                self.completion_matches = self.completecommands(text, line, begidx, endidx)
            else:
                self.completion_matches = self.completeparams(text, line, begidx, endidx)

        try:
            return self.completion_matches[state]
        except IndexError:
            return None
开发者ID:pmutha,项目名称:katello,代码行数:26,代码来源:shell.py


示例6: completer

def completer(text, state):
    global _last_line
    global _last_res
    global rl_completion_suppress_append
    if rl_completion_suppress_append is not None:
        rl_completion_suppress_append.value = 1
    try:
        line = readline.get_line_buffer()[:readline.get_endidx()]
        if _last_line != line:
            _last_res = _completer_get_subs(line)
            _last_line = line
        (dir, name, qtype, lastword, subs) = _last_res
        if state < len(subs):
            sn = subs[state]
            sn1 = sn.resolve('')  # deref symlinks
            fullname = os.path.join(dir, sn.name)
            if stat.S_ISDIR(sn1.mode):
                ret = shquote.what_to_add(qtype, lastword, fullname+'/',
                                          terminate=False)
            else:
                ret = shquote.what_to_add(qtype, lastword, fullname,
                                          terminate=True) + ' '
            return text + ret
    except Exception, e:
        log('\nerror in completion: %s\n' % e)
开发者ID:lkosewsk,项目名称:bup,代码行数:25,代码来源:ftp-cmd.py


示例7: completer

def completer(text, state):
    global _last_line
    global _last_res
    global rl_completion_suppress_append
    if rl_completion_suppress_append is not None:
        rl_completion_suppress_append.value = 1
    try:
        line = readline.get_line_buffer()[:readline.get_endidx()]
        if _last_line != line:
            _last_res = _completer_get_subs(line)
            _last_line = line
        (dir, name, qtype, lastword, subs) = _last_res
        if state < len(subs):
            sn = subs[state]
            sn1 = sn.try_resolve()  # find the type of any symlink target
            fullname = os.path.join(dir, sn.name)
            if stat.S_ISDIR(sn1.mode):
                ret = shquote.what_to_add(qtype, lastword, fullname+'/',
                                          terminate=False)
            else:
                ret = shquote.what_to_add(qtype, lastword, fullname,
                                          terminate=True) + ' '
            return text + ret
    except Exception, e:
        log('\n')
        try:
            import traceback
            traceback.print_tb(sys.exc_traceback)
        except Exception, e2:
            log('Error printing traceback: %s\n' % e2)
开发者ID:3v,项目名称:bup,代码行数:30,代码来源:ftp-cmd.py


示例8: complete

    def complete(self, text, state):  # pylint: disable=unused-argument
        '''
        Tab complete for the current step.
        '''

        if state == 0:
            parser = StatementParser(self.features)
            begidx = readline.get_begidx()
            endidx = readline.get_endidx()
            line = readline.get_line_buffer()
            prefix = line[begidx:endidx] if line else ''

            line = line[:endidx]
            if self.complete_single_token:
                # treat the entire line as a single token
                args = [line]
            else:
                # tokenize the line
                tokens = parser.tokenize(line)
                tokens = parser.condense(tokens)
                args = [t.text for t in tokens if isinstance(t, StringToken)]
            self.completions = self.active_step.complete(self, args, prefix)

        if state < len(self.completions):
            return self.completions[state]
        return None
开发者ID:ameily,项目名称:pypsi,代码行数:26,代码来源:wizard.py


示例9: complete

    def complete(self, text, state, plugin_scope=None):
        '''
        '''
        if state is 0:
            original_line = readline.get_line_buffer()

            completion_line = original_line[0:readline.get_endidx()]

            self.logger.debug('Command auto completion, user input: "%s", state is %s, completion_type is %s' \
                              % (original_line, state, readline.get_completion_type()))
            self.logger.debug('  begidx=%s endidx=%s completion_line="%s"' % (readline.get_begidx(), readline.get_endidx(), completion_line))

            self.completion_user_input = sysadmintoolkit.userinput.UserInput(completion_line, self, plugin_scope, completion=True)

            self.logger.debug('Completion matches are %s' % self.completion_user_input.completion_matches)

            if len(self.completion_user_input.completion_matches) is 0 or \
            (self.completion_user_input.status is 'label_conflict' and self.completion_user_input.input_keyword_list[-1] is not '' and self.completion_user_input.rest_of_line is not ''):
                self.print_error_on_user_input(self.completion_user_input)
                self.completion_matches = []
            elif len(self.completion_user_input.completion_matches) is 1:
                self.completion_user_input.completion_matches[0] += ' '

        try:
            return self.completion_user_input.completion_matches[state]
        except IndexError:
            return None
开发者ID:lpther,项目名称:SysadminToolkit,代码行数:27,代码来源:cmdprompt.py


示例10: complete

 def complete(self, text, state):
     if state == 0:
         origline = readline.get_line_buffer()
         line = origline.lstrip()
         # in case '|', ';', '&' used, take last part of line to complete
         line = re.split('&|\||;', line)[-1].lstrip()
         stripped = len(origline) - len(line)
         begidx = readline.get_begidx() - stripped
         endidx = readline.get_endidx() - stripped
         if line.split(' ')[0] == 'sudo' and len(line.split(' ')) <= 2:
             compfunc = self.completesudo
         elif len (line.split(' ')) > 1 \
              and line.split(' ')[0] in self.conf['allowed']:
             compfunc = self.completechdir
         elif 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:xiaoyang2008mmm,项目名称:zyshell,代码行数:30,代码来源:zyshell.py


示例11: complete

    def complete(self, text, state):
        if state == 0:
            import readline
            line_buf = readline.get_line_buffer()
            line = line_buf.lstrip()
            strip_len = len(line_buf) - len(line)
            begidx = readline.get_begidx() - strip_len
            endidx = readline.get_endidx() - strip_len

            if begidx > 0:
                cmd, arg, 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:zenaix,项目名称:ICSuit,代码行数:25,代码来源:cli.py


示例12: complete

def complete(input, state):
	"""Performs generic autocompletion action for whatever incomplete
	input string has been typed into the shell so far. Will be
	automatically called from somewhere in the `readline` module.

	Depending on the current content of `readline.get_line_buffer()`,
	this function retrieves a list of input terms which are
	considered likely to be in mind of the typing user, for instance
	because they begin with what the user has typed in so far.
	This list of candidate terms is put together by the :func:`~.commands.choices_left`
	function in the :mod:`.commands` module. Read its documentation for
	more information.
	"""
	# http://stackoverflow.com/a/5638688/1933494
	buf = readline.get_line_buffer()
	# http://doughellmann.com/2008/11/pymotw-readline.html
	# begin = readline.get_begidx()
	# end = readline.get_endidx()
	#sgst = [s+' ' for s in commands.choices_left(buf)]
	# range from position of currently handled term to that of cursor
	csrng = (readline.get_begidx(), readline.get_endidx())
	util.log('User input line: "{}"; current range {}'.format(buf, csrng))
	#print '{}-{}'.format(*csrng)
	sgst = [s for s in commands.choices_left(buf, csrng)]
	return sgst[state]
开发者ID:Cutuchiqueno,项目名称:kathaireo,代码行数:25,代码来源:__init__.py


示例13: complete

 def complete(self, text, state):
     """
     overwrite the origin complete function, but only change one line:
     self.completenames => self.complete_sequence_number
     """
     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.complete_sequence_number
         self.completion_matches = compfunc(text, line, begidx, endidx)
     try:
         return self.completion_matches[state]
     except IndexError:
         return None
开发者ID:henryluo,项目名称:acitoolkit,代码行数:28,代码来源:acitoolkitcli.py


示例14: complete

 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()
         line = origline.lstrip()
         # in case '|', ';', '&' used, take last part of line to complete
         line = re.split('&|\||;', line)[-1].lstrip()
         stripped = len(origline) - len(line)
         begidx = readline.get_begidx() - stripped
         endidx = readline.get_endidx() - stripped
         if line.split(' ')[0] == 'sudo' and len(line.split(' ')) <= 2:
             compfunc = self.completesudo
         elif len (line.split(' ')) > 1 \
              and line.split(' ')[0] in self.conf['allowed']:
             compfunc = self.completechdir
         elif 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:lberra,项目名称:lshell,代码行数:34,代码来源:shellcmd.py


示例15: complete

    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()

            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 so use all candidates
                        self.current_candidates = candidates

                except (KeyError, IndexError), err:
                    self.current_candidates = []
开发者ID:szaffarano,项目名称:demeter,代码行数:33,代码来源:utils.py


示例16: complete

    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:zongdeiqianxing,项目名称:routersploit,代码行数:33,代码来源:interpreter.py


示例17: complete

 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:
         if self.completion_matches:
             return self.completion_matches[state]
     except IndexError:
         return None
开发者ID:kai5263499,项目名称:pupy,代码行数:26,代码来源:PupyCmd.py


示例18: complete

    def complete(self, text, state):
        response = None
        if state == 0:
            origline = readline.get_line_buffer() 
            begin = readline.get_begidx() 
            end = readline.get_endidx() 
            being_completed = origline[begin:end]  
            words = origline.split() 
 
            if not words: 
                self.current_candidates = sorted(self.options)
            else:
                try:
                    if begin == 0: 
                        candidates = self.allcmd
                    else:
                        if origline.endswith(' '):words.append('')  
                        basedir,basefile = os.path.split(words[-1])
			if words[0].lower()=="select":
				candidates=alllocalpath("%s/cheung/data/hosts/"%HOME)
			else:
                        	candidates = alllocalpath(basedir)
                        being_completed = basefile
 
                    if being_completed: 
                        self.current_candidates = [ w for w in candidates
                                                    if w.startswith(being_completed) ]  
                    else:
                        self.current_candidates = candidates  
 
                except (KeyError, IndexError), err:
                    self.current_candidates = []
开发者ID:BillWang139967,项目名称:xbatch,代码行数:32,代码来源:command_tab.py


示例19: complete

    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.
        """
        ## todo: improve this thing to, eg, complete in the middle of a token
        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.complete_default
            if begidx > 0:
                parts = self._parse_line(line)
                if len(parts) > 0:
                    command = self.lookup(parts[0])
                    _compfunc = getattr(self, command.complete)
                    if _compfunc is not None and callable(_compfunc):
                        compfunc = _compfunc
            else:
                compfunc = self.complete_names
            self.completion_matches = compfunc(text, line, begidx, endidx)

        try:
            return self.completion_matches[state]
        except IndexError:
            return None
开发者ID:rshk,项目名称:CliApp,代码行数:30,代码来源:__init__.py


示例20: complete

    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

            # Complete parameters
            if begidx>0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    self.completion_matches = []
                else:
                    registered_command = self.get_registered_command(cmd)
                    if registered_command != None:
                        self.completion_matches = registered_command.complete(self.data, text, line, begidx, endidx)
                    else:
                        self.completion_matches = []
            # Complete function names
            else:
                self.completion_matches = self.completenames(text, line, begidx, endidx)

        try:
            return self.completion_matches[state]
        except IndexError:
            return None
开发者ID:niavok,项目名称:todomanager,代码行数:34,代码来源:shell.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python readline.get_history_item函数代码示例发布时间:2022-05-26
下一篇:
Python readline.get_current_history_length函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap