@contextlib.contextmanager<EOL><INDENT>def isolation(self, input=None, env=None, color=False):<DEDENT>
input = make_input_stream(input, self.charset)<EOL>old_stdin = sys.stdin<EOL>old_stdout = sys.stdout<EOL>old_stderr = sys.stderr<EOL>old_forced_width = clickpkg.formatting.FORCED_WIDTH<EOL>clickpkg.formatting.FORCED_WIDTH = <NUM_LIT><EOL>env = self.make_env(env)<EOL>if PY2:<EOL><INDENT>sys.stdout = sys.stderr = bytes_output = StringIO()<EOL>if self.echo_stdin:<EOL><INDENT>input = EchoingStdin(input, bytes_output)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>bytes_output = io.BytesIO()<EOL>if self.echo_stdin:<EOL><INDENT>input = EchoingStdin(input, bytes_output)<EOL><DEDENT>input = io.TextIOWrapper(input, encoding=self.charset)<EOL>sys.stdout = sys.stderr = io.TextIOWrapper(<EOL>bytes_output, encoding=self.charset)<EOL><DEDENT>sys.stdin = input<EOL>def visible_input(prompt=None):<EOL><INDENT>sys.stdout.write(prompt or '<STR_LIT>')<EOL>val = input.readline().rstrip('<STR_LIT:\r\n>')<EOL>sys.stdout.write(val + '<STR_LIT:\n>')<EOL>sys.stdout.flush()<EOL>return val<EOL><DEDENT>def hidden_input(prompt=None):<EOL><INDENT>sys.stdout.write((prompt or '<STR_LIT>') + '<STR_LIT:\n>')<EOL>sys.stdout.flush()<EOL>return input.readline().rstrip('<STR_LIT:\r\n>')<EOL><DEDENT>def _getchar(echo):<EOL><INDENT>char = sys.stdin.read(<NUM_LIT:1>)<EOL>if echo:<EOL><INDENT>sys.stdout.write(char)<EOL>sys.stdout.flush()<EOL><DEDENT>return char<EOL><DEDENT>default_color = color<EOL>def should_strip_ansi(stream=None, color=None):<EOL><INDENT>if color is None:<EOL><INDENT>return not default_color<EOL><DEDENT>return not color<EOL><DEDENT>old_visible_prompt_func = clickpkg.termui.visible_prompt_func<EOL>old_hidden_prompt_func = clickpkg.termui.hidden_prompt_func<EOL>old__getchar_func = clickpkg.termui._getchar<EOL>old_should_strip_ansi = clickpkg.utils.should_strip_ansi<EOL>clickpkg.termui.visible_prompt_func = visible_input<EOL>clickpkg.termui.hidden_prompt_func = hidden_input<EOL>clickpkg.termui._getchar = _getchar<EOL>clickpkg.utils.should_strip_ansi = should_strip_ansi<EOL>old_env = {}<EOL>try:<EOL><INDENT>for key, value in iteritems(env):<EOL><INDENT>old_env[key] = os.environ.get(key)<EOL>if value is None:<EOL><INDENT>try:<EOL><INDENT>del os.environ[key]<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>os.environ[key] = value<EOL><DEDENT><DEDENT>yield bytes_output<EOL><DEDENT>finally:<EOL><INDENT>for key, value in iteritems(old_env):<EOL><INDENT>if value is None:<EOL><INDENT>try:<EOL><INDENT>del os.environ[key]<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>os.environ[key] = value<EOL><DEDENT><DEDENT>sys.stdout = old_stdout<EOL>sys.stderr = old_stderr<EOL>sys.stdin = old_stdin<EOL>clickpkg.termui.visible_prompt_func = old_visible_prompt_func<EOL>clickpkg.termui.hidden_prompt_func = old_hidden_prompt_func<EOL>clickpkg.termui._getchar = old__getchar_func<EOL>clickpkg.utils.should_strip_ansi = old_should_strip_ansi<EOL>clickpkg.formatting.FORCED_WIDTH = old_forced_width<EOL><DEDENT>
A context manager that sets up the isolation for invoking of a
        command line tool.  This sets up stdin with the given input data
        and `os.environ` with the overrides from the given dictionary.
        This also rebinds some internals in Click to be mocked (like the
        prompt functionality).

        This is automatically done in the :meth:`invoke` method.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param input: the input stream to put into sys.stdin.
        :param env: the environment overrides as dictionary.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.