本文整理汇总了Python中readline.get_endidx方法的典型用法代码示例。如果您正苦于以下问题:Python readline.get_endidx方法的具体用法?Python readline.get_endidx怎么用?Python readline.get_endidx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.get_endidx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def complete(self, text, state):
""":type text: string
:param text: partial text to complete
:type state: integer
:param state: the number of times the user has pressed tab. If ``0``, generate a new list of candidates; otherwise, use the old one
:rtype: list of strings
:return: set of completions
"""
if state == 0:
line = readline.get_line_buffer()
begin = readline.get_begidx()
end = readline.get_endidx()
established = line[:begin]
active = line[begin:end]
self.candidates = self.mode.complete(established, active)
try:
return self.candidates[state]
except IndexError:
return None
示例2: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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.
"""
try:
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.completenames
self.completion_matches = compfunc(text, line, begidx, endidx)
except Exception:
pass
try:
return self.completion_matches[state]
except IndexError:
return None
示例3: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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:
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
示例4: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def complete(self, text, state):
line = readline.get_line_buffer()
line = line[:readline.get_endidx()]
# If last_word == "_" it means that there was spaces before
# and we want to complete a new arg
tmp_line = line + "_"
tokens = shlex.split(tmp_line)
last_tok = tokens[-1][:-1] # remove the _ on the last token
much = False
if state == 0:
if len(tokens) == 1:
i = 0
self.matches = []
for cmd in COMMANDS_ALPHA:
if cmd.startswith(last_tok):
self.matches.append(cmd + " ")
i += 1
if i == MAX_PRINT_COMPLETE:
much = True
break
else:
cmd = tokens[0]
if cmd in self.con.COMMANDS:
f = self.con.COMMANDS[cmd].callback_complete
if f is not None:
self.matches = f(len(tokens)-1, last_tok)
if self.matches is None:
much = True
if much:
print("\ntoo much possibilities")
return None
return self.matches[state]
示例5: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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:
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 None
示例6: complete_request
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def complete_request(self,text):
line = readline.get_line_buffer()
cursor_pos = readline.get_endidx()
# send completion request to kernel
# Give the kernel up to 0.5s to respond
msg_id = self.client.shell_channel.complete(text=text, line=line,
cursor_pos=cursor_pos)
msg = self.client.shell_channel.get_msg(timeout=self.timeout)
if msg['parent_header']['msg_id'] == msg_id:
return msg["content"]["matches"]
return []
示例7: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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
示例8: _complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def _complete(self, text: str, state: int) -> Optional[Sequence[str]]:
""" Return the next possible completion for `text`.
If a command has not been entered, then complete against command list.
Otherwise try to call specific command completer function 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 and line:
cmd, *_ = self._parse_line(line)
try:
complete_function = self._get_command(cmd).complete
except CommandError:
return
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
示例9: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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:
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
示例10: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
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:
return self.completion_matches[state]
except IndexError:
return None
#text : word match
#line : complete line
示例11: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def complete(self, token, state):
"""Return a possible completion for readline
This function is called with state starting at zero to get the
first completion, then one/two/three etc until you return None. The best
implementation is to generate the list when state==0, save it,
and provide members on each increase.
The default implementation extracts the current full input
from readline and then calls :meth:`complete_command` or
:meth:`complete_sql` as appropriate saving the results for
subsequent calls.
"""
if state==0:
import readline
# the whole line
line=readline.get_line_buffer()
# beginning and end(+1) of the token in line
beg=readline.get_begidx()
end=readline.get_endidx()
# Are we matching a command?
try:
if self._completion_first and line.startswith("."):
self.completions=self.complete_command(line, token, beg, end)
else:
self.completions=self.complete_sql(line, token, beg, end)
except:
# Readline swallows any exceptions we raise. We
# shouldn't be raising any so this is to catch that
import traceback; traceback.print_exc()
raise
if state>len(self.completions):
return None
return self.completions[state]
# Taken from https://sqlite.org/lang_keywords.html
示例12: completer
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
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)
示例13: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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:
import readline
old_delims = readline.get_completer_delims()
readline.set_completer_delims(old_delims.replace('#', ''))
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
示例14: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [as 别名]
def complete(self, text, state):
"""
auto-complete selection based on given text and state parameters
"""
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
if begidx > 0:
mod, args, foo = self.parseline(line)
if mod == '':
return self.complete_modules(text)[state]
elif not mod in self.modules:
logger.error("BUG: mod '{}' not found!".format(mod))
else:
module = self.modules[mod]
self.completion_matches = \
self.complete_functions(module, text, line, begidx, endidx)
else:
self.completion_matches = self.complete_modules(text)
try:
return self.completion_matches[state]
except IndexError:
return ['']
# Execute commands from Modules
示例15: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_endidx [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:
origline = readline.get_line_buffer()
# Offer completion just for commands that starts
# with the trigger :
if origline and not origline.startswith(':'):
return None
line = origline.lstrip().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:
if self.completion_matches[state].startswith('alias_'):
if self.session.get('default_shell') == 'shell_php':
return self.completion_matches[state][6:]
else:
return ''
else:
return self.completion_matches[state]
except IndexError:
return None