本文整理汇总了Python中readline.get_begidx函数的典型用法代码示例。如果您正苦于以下问题:Python get_begidx函数的具体用法?Python get_begidx怎么用?Python get_begidx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_begidx函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: tab_completer
def tab_completer(text, state):
"""Called by the readline lib to calculate possible completions"""
array_to_match = None
if readline.get_begidx() == 0:
# since we are at the start of the line
# we are matching commands
array_to_match = 'cmds'
match_list = CMD_ARG_DICT.get('cmds', {}).keys()
else:
# we are matching args
cmd_line = readline.get_line_buffer()[0:readline.get_begidx()]
cmd = shlex.split(cmd_line)[-1]
array_to_match = CMD_ARG_DICT.get('cmds', {}).get(cmd)
if array_to_match:
match_list = CMD_ARG_DICT[array_to_match]
else:
array_to_match = CMD_ARG_DICT.get('options', {}).get(cmd)
if array_to_match:
match_list = CMD_ARG_DICT[array_to_match]
else:
array_to_match = 'options'
match_list = CMD_ARG_DICT.get('options',{}).keys()
matches = [item for item in match_list
if item.upper().startswith(text.upper())]
try:
return matches[state]
except IndexError:
return None
开发者ID:nmcspadden,项目名称:ImagrConfigCreator,代码行数:29,代码来源:config_creator.py
示例2: 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
示例3: complete
def complete(text, state):
"""On tab press, return the next possible completion"""
rl_completion_append_character.value = '\0'
global completion_results
if state == 0:
line = readline.get_line_buffer()
if line.startswith(':'):
# Control command completion
completion_results = complete_control_command(line, text)
else:
if line.startswith('!') and text and line.startswith(text):
dropped_exclam = True
text = text[1:]
else:
dropped_exclam = False
completion_results = []
# Complete local paths
completion_results += complete_local_path(text)
# Complete from history
l = len(text)
completion_results += [w + ' ' for w in history_words if \
len(w) > l and w.startswith(text)]
if readline.get_begidx() == 0:
# Completing first word from $PATH
completion_results += [w + ' ' for w in user_commands_in_path \
if len(w) > l and w.startswith(text)]
completion_results = remove_dupes(completion_results)
if dropped_exclam:
completion_results = ['!' + r for r in completion_results]
if state < len(completion_results):
return completion_results[state]
completion_results = None
开发者ID:daniyalzade,项目名称:polysh,代码行数:33,代码来源:completion.py
示例4: get_begidx
def get_begidx ( self ):
if util.isPlatformWindows ():
import pyreadline
return Readline ().get_begidx ()
else:
import readline
return readline.get_begidx ()
开发者ID:Juniper,项目名称:OpenClos,代码行数:7,代码来源:cli.py
示例5: complete_readline
def complete_readline(self, text, state):
log.debug("complete_readline: text:%s, state:%s", text, state)
response = None
if state == 0:
# This is the first time we are called for this text, so build a match list.
import readline
line = readline.get_line_buffer()
words = line.split()
index = readline.get_begidx()
current = text
first = ""
if len(words) > 0:
first = words[0]
try:
if len(current) == 0:
previous = words[-1]
else:
previous = words[-2]
except IndexError:
previous = ""
self.current_candidates = self.complete(first, current, previous, words, index)
try:
response = self.current_candidates[state]
if len(self.current_candidates) == 1:
# Add space if there is only one candidate
response = "{} ".format(response)
except IndexError:
response = None
log.debug("complete_readline(%s, %s) => %s", repr(text), state, response)
return response
开发者ID:asteven,项目名称:cli,代码行数:31,代码来源:complete.py
示例6: 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
示例7: 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
示例8: 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
示例9: complete
def complete(self, text, state):
reponse = 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()
try:
if begin == end:
candidates = self.getCandidateList(words, [self.entry])
else:
candidates = self.getCandidateList(words[0:-1], [self.entry])
if being_completed:
self.candidates = [ w+' ' for w in candidates
if w.startswith(being_completed) ]
else:
self.candidates = candidates
except err:
self.candidates = []
try:
response = self.candidates[state]
except IndexError:
reponse = None
return response
开发者ID:gyscos,项目名称:USC,代码行数:32,代码来源:completer.py
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例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:
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
示例17: 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
# 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
开发者ID:0x0mar,项目名称:phpsploit,代码行数:35,代码来源:shell.py
示例18: 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
示例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.
"""
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
示例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:
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
注:本文中的readline.get_begidx函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论