本文整理汇总了Python中readline.get_endidx函数的典型用法代码示例。如果您正苦于以下问题:Python get_endidx函数的具体用法?Python get_endidx怎么用?Python get_endidx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_endidx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例3: get_endidx
def get_endidx ( self ):
if util.isPlatformWindows ():
import pyreadline
return Readline ().get_endidx ()
else:
import readline
return readline.get_endidx ()
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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]
示例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
示例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
示例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 = []