How to use the argcomplete.compat.ensure_bytes function in argcomplete

To help you get started, we’ve selected a few argcomplete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kislyuk / argcomplete / argcomplete / __init__.py View on Github external
def debug(*args):
    if _DEBUG:
        if USING_PYTHON2:
            # debug_stream has to be binary mode in Python 2.
            # Attempting to write unicode directly uses the default ascii conversion.
            # Convert any unicode to bytes, leaving non-string input alone.
            args = [ensure_bytes(x) if isinstance(x, str) else x for x in args]
        print(file=debug_stream, *args)
github Azure / azure-cli / src / command_modules / azure-cli-interactive / azure / cli / command_modules / interactive / azclishell / argfinder.py View on Github external
def get_parsed_args(self, comp_words):
        """ gets the parsed args from a patched parser """
        active_parsers = self._patch_argument_parser()

        parsed_args = argparse.Namespace()

        self.completing = True
        if USING_PYTHON2:
            # Python 2 argparse only properly works with byte strings.
            comp_words = [ensure_bytes(word) for word in comp_words]

        try:
            active_parsers[0].parse_known_args(comp_words, namespace=parsed_args)
        except BaseException:
            pass

        self.completing = False
        return parsed_args
github kislyuk / argcomplete / argcomplete / __init__.py View on Github external
def _get_completions(self, comp_words, cword_prefix, cword_prequote, last_wordbreak_pos):
        active_parsers = self._patch_argument_parser()

        parsed_args = argparse.Namespace()
        self.completing = True

        if USING_PYTHON2:
            # Python 2 argparse only properly works with byte strings.
            comp_words = [ensure_bytes(word) for word in comp_words]

        try:
            debug("invoking parser with", comp_words[1:])
            with mute_stderr():
                a = self._parser.parse_known_args(comp_words[1:], namespace=parsed_args)
            debug("parsed args:", a)
        except BaseException as e:
            debug("\nexception", type(e), str(e), "while parsing args")

        self.completing = False

        if "--" in comp_words:
            self.always_complete_options = False

        completions = self.collect_completions(active_parsers, parsed_args, cword_prefix, debug)
        completions = self.filter_completions(completions)
github Azure / azure-cli-shell / azclishell / argfinder.py View on Github external
def get_parsed_args(self, comp_words):
        """ gets the parsed args from a patched parser """
        active_parsers = self._patch_argument_parser()

        parsed_args = argparse.Namespace()

        self.completing = True
        if USING_PYTHON2:
            # Python 2 argparse only properly works with byte strings.
            comp_words = [ensure_bytes(word) for word in comp_words]

        try:
            stderr = sys.stderr
            sys.stderr = os.open(os.devnull, "w")

            active_parsers[0].parse_known_args(comp_words, namespace=parsed_args)

            sys.stderr.close()
            sys.stderr = stderr
        except BaseException:
            pass

        self.completing = False
        return parsed_args
github Azure / azure-cli-extensions / src / interactive / azext_interactive / azclishell / argfinder.py View on Github external
def get_parsed_args(self, comp_words):
        """ gets the parsed args from a patched parser """
        active_parsers = self._patch_argument_parser()

        parsed_args = argparse.Namespace()

        self.completing = True
        if USING_PYTHON2:
            # Python 2 argparse only properly works with byte strings.
            comp_words = [ensure_bytes(word) for word in comp_words]

        try:
            active_parsers[0].parse_known_args(comp_words, namespace=parsed_args)
        except BaseException:  # pylint: disable=broad-except
            pass

        self.completing = False
        return parsed_args