本文整理汇总了Python中readline.get_line_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python readline.get_line_buffer方法的具体用法?Python readline.get_line_buffer怎么用?Python readline.get_line_buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.get_line_buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [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: autocomplete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def autocomplete(text, state):
""" Generic readline completion entry point. """
buffer = readline.get_line_buffer()
comp = completion_list
if not is_case_sensitive:
buffer = buffer.lower()
comp = [c.lower() for c in completion_list]
results = [c for c in comp if c.startswith(buffer)] + [None]
# Handle multi-word inputs by truncating strings at the last space
if buffer.find(' ') > 0:
strip_pos = buffer.rfind(' ') + 1
results = [i[strip_pos:] for i in results if i is not None] + [None]
return results[state]
示例3: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline 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.
"""
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
示例4: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
if state == 0: # on first trigger, build possible matches
if readline.get_line_buffer().startswith("use_module "):
self.matches = [s for s in self.modules if s and s.startswith(text)]
elif readline.get_line_buffer().startswith("use_report "):
self.matches = [s for s in self.reports if s and s.startswith(text)]
elif text: # cache matches (entries that start with entered text)
self.matches = [s for s in self.options if s and s.startswith(text)]
else: # no text entered, all matches possible
self.matches = self.options[:]
# return match indexed by state
try:
return self.matches[state]
except IndexError:
return None
示例5: print
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def print(self, text):
current_input = readline.get_line_buffer()
delete_chars = len(self.query) + len(current_input)
# remove the input:
sys.stdout.flush()
for i in range(delete_chars):
sys.stdout.write("\b \b")
# end for
sys.stdout.write("\033[K")
sys.stdout.flush()
# actual output
sys.stdout.write(str(text))
sys.stdout.write("\n")
sys.stdout.flush()
# load back the input
sys.stdout.write(self.query)
sys.stdout.flush()
sys.stdout.write(current_input)
sys.stdout.flush()
readline.redisplay()
# end def
示例6: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
"Generic readline completion entry point."
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
# show all commands
if not line:
return [c + ' ' for c in self.commands][state]
# account for last argument ending in a space
if RE_SPACE.match(buffer):
line.append('')
# resolve command to the implementation function
cmd = line[0].strip()
if cmd in self.commands:
impl = getattr(self, 'complete_%s' % cmd)
args = line[1:]
if args:
return (impl(args) + [None])[state]
return [cmd + ' '][state]
results = [c + ' ' for c in self.commands if c.startswith(cmd)] + [None]
return results[state]
示例7: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
if self.RE_SPACE.match(buffer):
line.append('')
cmd = line[0].strip()
if cmd in Command.COMMANDS:
impl = getattr(self, 'complete_%s' % cmd)
args = line[1:]
if args:
return (impl(args) + [None])[state]
return [cmd + ' '][state]
results = [c + ' ' for c in Command.COMMANDS if c.startswith(cmd)] + [None]
return results[state]
示例8: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
"Generic readline completion entry point."
# dexnet entity tab completion
results = [w for w in self.words if w.startswith(text)] + [None]
if results != [None]:
return results[state]
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
# dexnet entity tab completion
results = [w for w in self.words if w.startswith(text)] + [None]
if results != [None]:
return results[state]
# account for last argument ending in a space
if RE_SPACE.match(buffer):
line.append('')
return (self.complete_extra(line) + [None])[state]
# dexnet entity tab completion
示例9: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
"Generic readline completion entry point."
# dexnet entity tab completion
results = [w for w in self.words if w.startswith(text)] + [None]
if results != [None]:
return results[state]
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
# dexnet entity tab completion
results = [w for w in self.words if w.startswith(text)] + [None]
if results != [None]:
return results[state]
# account for last argument ending in a space
if RE_SPACE.match(buffer):
line.append('')
return (self.complete_extra(line) + [None])[state]
# dexnet entity tab completion
示例10: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def complete(self, text, state):
buffer = readline.get_line_buffer()
line = buffer.split()
if not line:
return [cmd + ' ' for cmd in self.COMMANDS][state]
EXPR = re.compile('.*\s+$', re.M)
if EXPR.match(buffer):
line.append('')
command = line[0].strip()
if command in self.COMMANDS:
command_function = getattr(self, 'complete_%s' % command)
args = line[1:]
if args:
return (command_function(args) + [None])[state]
return [command + ' '][state]
results = [cmd + ' ' for cmd in self.COMMANDS if cmd.startswith(command)] + [None]
return results[state]
示例11: _print
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def _print(msg):
line_buffer = readline.get_line_buffer()
# Clearing prompt
sys.stdout.write("\r")
sys.stdout.write("\033[K")
sys.stdout.write(str(msg))
# Restoring prompt
sys.stdout.write("\n%s" % ishell._current_prompt)
if line_buffer:
sys.stdout.write(" %s" % line_buffer)
sys.stdout.flush()
示例12: walk
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def walk(self, buf, state, run=False, full_line=None):
# Current commands in line
line = readline.get_line_buffer()
line_commands = line.split()
if run:
line_commands = buf.split()
logger.debug("Line=>%s" % line_commands)
if not line and not buf and not run:
completions = self.completions() + [None]
return completions[state]
# Traversing current command
for cmd_name in line_commands:
if self.is_child(cmd_name):
logger.debug("Found existing command=>%s" % cmd_name)
cmd = self.get_command(cmd_name)
return cmd.complete(line_commands[1:], buf, state, run, full_line)
if run:
print("Unknown Command: %s" % buf)
self.print_childs_help()
return
# Needing completion
logger.debug('buffer=> %s, state=>%s' % (buf, state))
tokens = buf.split()
logger.debug('tokens=>%s' % tokens)
# Nothing was provided, running root completion
completions = self.completions(tokens[0])
completions += [None]
logger.debug('completions=>%s' % completions)
logger.debug('END COMPLETE')
return completions[state]
示例13: completer
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [as 别名]
def completer():
# source: https://gist.github.com/iamatypeofwalrus/5637895
class tabCompleter(object):
def pathCompleter(self,text,state):
line = readline.get_line_buffer().split()
return [x for x in glob(text+'*')][state]
def createListCompleter(self,ll):
pass
def listCompleter(text,state):
line = readline.get_line_buffer()
if not line:
return None
else:
return [c + " " for c in ll if c.startswith(line)][state]
self.listCompleter = listCompleter
t = tabCompleter()
# tool command
t.createListCompleter(["clear", "exit", "banner","exec","restart", "upgrade", 'search'
# modules
# auxiliary modules
,"use auxiliary/gather/ip_gather","use auxiliary/gather/ip_lookup", "use auxiliary/core/pyconverter"
# exploit modules
,"use exploit/windows/ftp/ftpshell_overflow", "use exploit/android/login/login_bypass", "use exploit/windows/http/oracle9i_xdb_pass"])
readline.set_completer_delims('\t')
readline.parse_and_bind("tab: complete")
readline.set_completer(t.listCompleter)
示例14: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline 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:
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
示例15: complete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_line_buffer [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]