Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
##############################
# completions = self._get_completions(comp_words, cword_prefix, cword_prequote, last_wordbreak_pos)
# capture stdout from the autocompleter
result = StringIO()
with redirect_stdout(result):
completions = completer.complete_command(tokens, tokens[-1], comp_line, begidx, endidx)
outstr = result.getvalue()
if completions:
# If any completion has a space in it, then quote all completions
# this improves the user experience so they don't nede to go back and add a quote
if ' ' in ''.join(completions):
completions = ['"{}"'.format(entry) for entry in completions]
argcomplete.debug("\nReturning completions:", completions)
output_stream.write(ifs.join(completions).encode(argcomplete.sys_encoding))
elif outstr:
# if there are no completions, but we got something from stdout, try to print help
# trick the bash completion into thinking there are 2 completions that are unlikely
# to ever match.
comp_type = int(os.environ["COMP_TYPE"])
if comp_type == 63: # type is 63 for second tab press
print(outstr.rstrip(), file=argcomplete.debug_stream, end='')
if completions is not None:
output_stream.write(ifs.join([ifs, ' ']).encode(argcomplete.sys_encoding))
else:
output_stream.write(ifs.join([]).encode(argcomplete.sys_encoding))
else:
validator=validator, print_suppressed=print_suppressed)
if "_ARGCOMPLETE" not in os.environ:
# not an argument completion invocation
return
try:
argcomplete.debug_stream = os.fdopen(9, "w")
except IOError:
argcomplete.debug_stream = sys.stderr
if output_stream is None:
try:
output_stream = os.fdopen(8, "wb")
except IOError:
argcomplete.debug("Unable to open fd 8 for writing, quitting")
exit_method(1)
ifs = os.environ.get("_ARGCOMPLETE_IFS", "\013")
if len(ifs) != 1:
argcomplete.debug("Invalid value for IFS, quitting [{v}]".format(v=ifs))
exit_method(1)
comp_line = os.environ["COMP_LINE"]
comp_point = int(os.environ["COMP_POINT"])
comp_line = argcomplete.ensure_str(comp_line)
##############################
# SWAPPED FOR AUTOCOMPLETER
#
# Replaced with our own tokenizer function
try:
argcomplete.debug_stream = os.fdopen(9, "w")
except IOError:
argcomplete.debug_stream = sys.stderr
if output_stream is None:
try:
output_stream = os.fdopen(8, "wb")
except IOError:
argcomplete.debug("Unable to open fd 8 for writing, quitting")
exit_method(1)
ifs = os.environ.get("_ARGCOMPLETE_IFS", "\013")
if len(ifs) != 1:
argcomplete.debug("Invalid value for IFS, quitting [{v}]".format(v=ifs))
exit_method(1)
comp_line = os.environ["COMP_LINE"]
comp_point = int(os.environ["COMP_POINT"])
comp_line = argcomplete.ensure_str(comp_line)
##############################
# SWAPPED FOR AUTOCOMPLETER
#
# Replaced with our own tokenizer function
##############################
tokens, _, begidx, endidx = tokens_for_completion(comp_line, comp_point)
# _ARGCOMPLETE is set by the shell script to tell us where comp_words
# should start, based on what we're completing.