Added lazy file opening
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 81930b5 · Browse files · 14 files·+415 added−248 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+415 added−248 removed
- tests:+6 added−6 removed
- other:+409 added−242 removed
Provenance
- Commit
f270dd2- Tree
392e047- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
81930b5
14 files changed+415 added−248 removed
modified:click/__init__.py+12 added-6 removed
25 unmodified lines26 # Types27 from .types import ParamType, File, Choice, IntRange, STRING, INT, FLOAT, \28 BOOL, UUID29 30-# Helper functions31-from .helpers import prompt, confirm, get_terminal_size, echo, echo_via_pager30+# Utilities31+from .utils import echo32 33+# Terminal functions34+from .termui import prompt, confirm, get_terminal_size, echo_via_pager35+36 # Exceptions34-from .exceptions import UsageError, Abort37+from .exceptions import ClickException, UsageError, FileError, Abort38 39 # Formatting40 from .formatting import HelpFormatter, wrap_text41 11 unmodified lines53 # Types54 'ParamType', 'File', 'Choice', 'IntRange', 'STRING', 'INT', 'FLOAT',55 'BOOL', 'UUID',56 54- # Helper functions55- 'prompt', 'confirm', 'get_terminal_size', 'echo', 'echo_via_pager',57+ # Utilities58+ 'echo',59 60+ # Terminal functions61+ 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',62+63 # Exceptions58- 'UsageError', 'Abort',64+ 'ClickException', 'UsageError', 'FileError', 'Abort',65 66 # Formatting67 'HelpFormatter', 'wrap_text',68 ]modified:click/_compat.py+26 added
40 unmodified lines41 if encoding is None:42 encoding = sys.stdin.encoding43 f = _wrap_stream_for_codec(f, encoding, errors)44 return f, False45+46+ def filename_to_ui(value):47+ if isinstance(value, bytes):48+ value = value.decode(sys.getfilesystemencoding(), 'replace')49+ return value50 else:51 import io52 text_type = str53 raw_input = input29 unmodified lines83 if encoding is not None:84 f = _wrap_stream_for_codec(f, encoding, errors)85 86 return f, False87+88+ def filename_to_ui(value):89+ if isinstance(value, bytes):90+ value = value.decode(sys.getfilesystemencoding(), 'replace')91+ else:92+ value = value.encode('utf-8', 'surrogateescape') \93+ .decode('utf-8', 'replace')94+ return value95+96+97+def get_streerror(e, default=None):98+ if hasattr(e, 'strerror'):99+ msg = e.strerror100+ else:101+ if default is not None:102+ msg = default103+ else:104+ msg = str(e)105+ if isinstance(msg, bytes):106+ msg = msg.decode('utf-8', 'replace')107+ return msgmodified:click/core.py+6 added-8 removed
2 unmodified lines3 import codecs4 from itertools import chain5 6 from .types import convert_type, IntRange, BOOL7-from .utils import make_str, make_default_short_help8-from .exceptions import UsageError, Abort9-from .helpers import prompt, confirm, echo7+from .utils import make_str, make_default_short_help, echo8+from .exceptions import ClickException, UsageError, Abort9+from .termui import prompt, confirm10 from .formatting import HelpFormatter11 from .parser import OptionParser12 13 from ._compat import PY2, isidentifier419 unmodified lines433 ctx.exit()434 except (EOFError, KeyboardInterrupt):435 echo(file=sys.stderr)436 raise Abort()437- except UsageError as e:438- if e.ctx is not None:439- echo(e.ctx.get_usage() + '\n', file=sys.stderr)440- echo('Error: %s' % e.message, file=sys.stderr)441- sys.exit(2)437+ except ClickException as e:438+ e.show()439+ sys.exit(e.exit_code)440 except Abort:441 echo('Aborted!', file=sys.stderr)442 sys.exit(1)443 594 unmodified linesmodified:click/decorators.py+1 added-1 removed
1 import inspect2 3 from functools import update_wrapper4 5-from .helpers import echo5+from .utils import echo6 7 8 def pass_context(f):9 """Marks a callback that it wants to receive the current context256 unmodified linesmodified:click/exceptions.py+38 added-6 removed
1-from ._compat import PY21+from ._compat import PY2, filename_to_ui2+from .utils import echo3 4 4-class UsageError(Exception):5- """An internal exception that signals a usage error. This typically6- aborts any further handling.7- """5+class ClickException(Exception):6+ """An exception that click can handle and show to the user.."""7 8+ #: The exit code for this exception9+ exit_code = 110+9- def __init__(self, message, ctx=None):11+ def __init__(self, message):12 if PY2:13 Exception.__init__(self, message.encode('utf-8'))14 else:15 Exception.__init__(self, message)16 self.message = message17+18+ def show(self, file=None):19+ echo('Error: %s' % self.message)20+21+22+class UsageError(ClickException):23+ """An internal exception that signals a usage error. This typically24+ aborts any further handling.25+ """26+ exit_code = 227+28+ def __init__(self, message, ctx=None):29+ ClickException.__init__(self, message)30 self.ctx = ctx31 32+ def show(self, file=None):33+ echo(self.ctx.get_usage() + '\n', file=file)34+ echo('Error: %s' % self.message, file=file)35 36+37+class FileError(ClickException):38+ """Raised if a file cannot be opened."""39+40+ def __init__(self, filename, hint=None):41+ ui_filename = filename_to_ui(filename)42+ if hint is None:43+ hint = 'unknown error'44+ message = 'Could not open file %s: %s' % (filename, hint)45+ ClickException.__init__(self, message)46+ self.ui_filename = ui_filename47+ self.filename = filename48+49+50 class Abort(RuntimeError):51 """An internal signalling exception that signals click to abort."""modified:click/formatting.py+1 added-1 removed
1 import textwrap2 from contextlib import contextmanager3 4-from .helpers import get_terminal_size4+from .termui import get_terminal_size5 6 7 def measure_table(rows):8 widths = {}219 unmodified linesdeleted:click/helpers.py-195 removed
1-import os2-import sys3-import struct4-5-from ._compat import raw_input, PY2, text_type, string_types6-from .utils import get_best_encoding7-from .exceptions import Abort, UsageError8-from .types import convert_type9-10-11-# The prompt functions to use. The doc tools currently override these12-# functions to customize how they work.13-visible_prompt_func = raw_input14-15-16-def hidden_prompt_func(prompt):17- import getpass18- return getpass.getpass(prompt)19-20-21-def prompt(text, default=None, hide_input=False,22- confirmation_prompt=False, type=None,23- value_proc=None):24- """Prompts a user for input. This is a convenience function that can25- be used to prompt a user for input later.26-27- If the user aborts the input by sending a interrupt signal this28- function will catch it and raise a :exc:`Abort` exception.29-30- :param text: the text to show for the prompt.31- :param default: the default value to use if no input happens. If this32- is not given it will prompt until it's aborted.33- :param hide_input: if this is set to true then the input value will34- be hidden.35- :param confirmation_prompt: asks for confirmation for the value.36- :param type: the type to use to check the value against.37- :param value_proc: if this parameter is provided it's a function that38- is invoked instead of the type conversion to39- convert a value.40- """41- result = None42-43- def prompt_func(text):44- f = hide_input and hidden_prompt_func or visible_prompt_func45- try:46- return f(text)47- except (KeyboardInterrupt, EOFError):48- raise Abort()49-50- if value_proc is None:51- value_proc = convert_type(type, default)52-53- prompt = text54- if default is not None:55- prompt = '%s [%s]' % (prompt, default)56- prompt += ': '57-58- while 1:59- while 1:60- value = prompt_func(prompt)61- if value:62- break63- # If a default is set and used, then the confirmation64- # prompt is always skipped because that's the only thing65- # that really makes sense.66- elif default is not None:67- return default68- try:69- result = value_proc(value)70- except UsageError as e:71- echo('Error: %s' % e.message)72- continue73- if not confirmation_prompt:74- return result75- while 1:76- value2 = prompt_func('Repeat for confirmation: ')77- if value2:78- break79- if value == value2:80- return result81- echo('Error: the two entered values do not match')82-83-84-def confirm(text, default=False, abort=False):85- """Prompts for confirmation (yes/no question).86-87- If the user aborts the input by sending a interrupt signal this88- function will catch it and raise a :exc:`Abort` exception.89-90- :param text: the question to ask.91- :param default: the default for the prompt.92- :param abort: if this is set to `True` a negative answer aborts the93- exception by raising :exc:`Abort`.94- """95- prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')96- while 1:97- try:98- value = visible_prompt_func(prompt).lower().strip()99- except (KeyboardInterrupt, EOFError):100- raise Abort()101- if value in ('y', 'yes'):102- rv = True103- elif value in ('n', 'no'):104- rv = False105- elif value == '':106- rv = default107- else:108- echo('Error: invalid input')109- continue110- break111- if abort and not rv:112- raise Abort()113- return rv114-115-116-def get_terminal_size():117- """Returns the current size of the terminal as tuple in the form118- ``(width, height)`` in columns and rows.119- """120- # If shutil has get_terminal_size() (Python 3.3 and later) use that121- if sys.version_info >= (3, 3):122- import shutil123- shutil_get_terminal_size = getattr(shutil, 'get_terminal_size', None)124- if shutil_get_terminal_size:125- sz = shutil_get_terminal_size()126- return sz.columns, sz.lines127-128- def ioctl_gwinsz(fd):129- try:130- import fcntl131- import termios132- cr = struct.unpack(133- 'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))134- except Exception:135- return136- return cr137-138- cr = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)139- if not cr:140- try:141- fd = os.open(os.ctermid(), os.O_RDONLY)142- try:143- cr = ioctl_gwinsz(fd)144- finally:145- os.close(fd)146- except Exception:147- pass148- if not cr or not cr[0] or not cr[1]:149- cr = (os.environ.get('LINES', 25),150- os.environ.get('COLUMNS', 80))151- return int(cr[1]), int(cr[0])152-153-154-def echo(message=None, file=None):155- """Prints a message plus a newline to the given file or stdout. On156- first sight this looks like the print function but it has improved157- support for handling unicode data that does not fail no matter how158- badly configured the system is.159-160- :param message: the message to print161- :param file: the file to write to (defaults to ``stdout``)162- """163- if file is None:164- file = sys.stdout165- if message is not None:166- if not isinstance(message, string_types):167- message = text_type(message)168- if message:169- if PY2 and isinstance(message, text_type):170- encoding = get_best_encoding(file)171- message = message.encode(encoding, 'replace')172- file.write(message)173- file.write('\n')174- file.flush()175-176-177-def echo_via_pager(text):178- """This function takes a text and shows it via an environment specific179- pager on stdout.180-181- :param text: the text to page.182- """183- if not isinstance(text, string_types):184- text = text_type(text)185-186- if PY2 and isinstance(text, text_type):187- encoding = get_best_encoding(sys.stdout)188- text = text.encode(encoding, 'replace')189-190- # Pydoc's pager is badly broken with LANG=C on Python 3 to the point191- # where it will corrupt the terminal. http://bugs.python.org/issue21398192- # I don't feel like reimplementing it given that it works on Python 2193- # and seems reasonably stable otherwise.194- import pydoc195- pydoc.pager(text)added:click/termui.py+172 added
1+import os2+import sys3+import struct4+5+from ._compat import raw_input, PY2, text_type, string_types6+from .utils import get_best_encoding, echo7+from .exceptions import Abort, UsageError8+from .types import convert_type9+10+11+# The prompt functions to use. The doc tools currently override these12+# functions to customize how they work.13+visible_prompt_func = raw_input14+15+16+def hidden_prompt_func(prompt):17+ import getpass18+ return getpass.getpass(prompt)19+20+21+def prompt(text, default=None, hide_input=False,22+ confirmation_prompt=False, type=None,23+ value_proc=None):24+ """Prompts a user for input. This is a convenience function that can25+ be used to prompt a user for input later.26+27+ If the user aborts the input by sending a interrupt signal this28+ function will catch it and raise a :exc:`Abort` exception.29+30+ :param text: the text to show for the prompt.31+ :param default: the default value to use if no input happens. If this32+ is not given it will prompt until it's aborted.33+ :param hide_input: if this is set to true then the input value will34+ be hidden.35+ :param confirmation_prompt: asks for confirmation for the value.36+ :param type: the type to use to check the value against.37+ :param value_proc: if this parameter is provided it's a function that38+ is invoked instead of the type conversion to39+ convert a value.40+ """41+ result = None42+43+ def prompt_func(text):44+ f = hide_input and hidden_prompt_func or visible_prompt_func45+ try:46+ return f(text)47+ except (KeyboardInterrupt, EOFError):48+ raise Abort()49+50+ if value_proc is None:51+ value_proc = convert_type(type, default)52+53+ prompt = text54+ if default is not None:55+ prompt = '%s [%s]' % (prompt, default)56+ prompt += ': '57+58+ while 1:59+ while 1:60+ value = prompt_func(prompt)61+ if value:62+ break63+ # If a default is set and used, then the confirmation64+ # prompt is always skipped because that's the only thing65+ # that really makes sense.66+ elif default is not None:67+ return default68+ try:69+ result = value_proc(value)70+ except UsageError as e:71+ echo('Error: %s' % e.message)72+ continue73+ if not confirmation_prompt:74+ return result75+ while 1:76+ value2 = prompt_func('Repeat for confirmation: ')77+ if value2:78+ break79+ if value == value2:80+ return result81+ echo('Error: the two entered values do not match')82+83+84+def confirm(text, default=False, abort=False):85+ """Prompts for confirmation (yes/no question).86+87+ If the user aborts the input by sending a interrupt signal this88+ function will catch it and raise a :exc:`Abort` exception.89+90+ :param text: the question to ask.91+ :param default: the default for the prompt.92+ :param abort: if this is set to `True` a negative answer aborts the93+ exception by raising :exc:`Abort`.94+ """95+ prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')96+ while 1:97+ try:98+ value = visible_prompt_func(prompt).lower().strip()99+ except (KeyboardInterrupt, EOFError):100+ raise Abort()101+ if value in ('y', 'yes'):102+ rv = True103+ elif value in ('n', 'no'):104+ rv = False105+ elif value == '':106+ rv = default107+ else:108+ echo('Error: invalid input')109+ continue110+ break111+ if abort and not rv:112+ raise Abort()113+ return rv114+115+116+def get_terminal_size():117+ """Returns the current size of the terminal as tuple in the form118+ ``(width, height)`` in columns and rows.119+ """120+ # If shutil has get_terminal_size() (Python 3.3 and later) use that121+ if sys.version_info >= (3, 3):122+ import shutil123+ shutil_get_terminal_size = getattr(shutil, 'get_terminal_size', None)124+ if shutil_get_terminal_size:125+ sz = shutil_get_terminal_size()126+ return sz.columns, sz.lines127+128+ def ioctl_gwinsz(fd):129+ try:130+ import fcntl131+ import termios132+ cr = struct.unpack(133+ 'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))134+ except Exception:135+ return136+ return cr137+138+ cr = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)139+ if not cr:140+ try:141+ fd = os.open(os.ctermid(), os.O_RDONLY)142+ try:143+ cr = ioctl_gwinsz(fd)144+ finally:145+ os.close(fd)146+ except Exception:147+ pass148+ if not cr or not cr[0] or not cr[1]:149+ cr = (os.environ.get('LINES', 25),150+ os.environ.get('COLUMNS', 80))151+ return int(cr[1]), int(cr[0])152+153+154+def echo_via_pager(text):155+ """This function takes a text and shows it via an environment specific156+ pager on stdout.157+158+ :param text: the text to page.159+ """160+ if not isinstance(text, string_types):161+ text = text_type(text)162+163+ if PY2 and isinstance(text, text_type):164+ encoding = get_best_encoding(sys.stdout)165+ text = text.encode(encoding, 'replace')166+167+ # Pydoc's pager is badly broken with LANG=C on Python 3 to the point168+ # where it will corrupt the terminal. http://bugs.python.org/issue21398169+ # I don't feel like reimplementing it given that it works on Python 2170+ # and seems reasonably stable otherwise.171+ import pydoc172+ pydoc.pager(text)modified:click/types.py+29 added-16 removed
1 import sys2 import uuid3 4-from ._compat import open_stream, text_type4+from ._compat import open_stream, text_type, filename_to_ui, get_streerror5 from .exceptions import UsageError6-from .utils import safecall6+from .utils import safecall, LazyFile7 8 9 class ParamType(object):10 """Helper for converting values through types. The following is207 unmodified lines218 See :ref:`file-args` for more information.219 """220 name = 'filename'221 222- def __init__(self, mode='r', encoding=None, errors='strict'):222+ def __init__(self, mode='r', encoding=None, errors='strict', lazy=None):223 self.mode = mode224 self.encoding = encoding225 self.errors = errors226+ self.lazy = lazy227 228+ def resolve_lazy_flag(self, value):229+ if self.lazy is not None:230+ return self.lazy231+ if value == '-':232+ return False233+ elif 'w' in self.mode:234+ return True235+ return False236+237 def convert(self, value, param, ctx):238 try:239 if hasattr(value, 'read') or hasattr(value, 'write'):240 return value231- f, was_opened = open_stream(value, self.mode, self.encoding,232- self.errors)241+242+ lazy = self.resolve_lazy_flag(value)243+244+ if lazy:245+ f = LazyFile(value, self.mode, self.encoding, self.errors)246+ if ctx is not None:247+ ctx.call_on_close(f.close_intelligently)248+ return f249+250+ f, should_close = open_stream(value, self.mode,251+ self.encoding, self.errors)252 # If a context is provided we automatically close the file253 # at the end of the context execution (or flush out). If a254 # context does not exist it's the caller's responsibility to255 # properly close the file. This for instance happens when the256 # type is used with prompts.257 if ctx is not None:239- if was_opened:258+ if should_close:259 ctx.call_on_close(safecall(f.close))260 else:261 ctx.call_on_close(safecall(f.flush))262 return f263 except (IOError, OSError) as e:245- if isinstance(value, bytes):246- value = value.decode(sys.getfilesystemencoding(), 'replace')247- if hasattr(e, 'strerror'):248- msg = e.strerror249- else:250- msg = str(e)251- if isinstance(msg, bytes):252- msg = msg.decode('utf-8', 'replace')253- self.fail('Could not open file %s: %s' % (value, msg),254- param, ctx)264+ self.fail('Could not open file: %s: %s' % (265+ filename_to_ui(value),266+ get_streerror(e),267+ ), param, ctx)268 269 270 def convert_type(ty, default=None):271 """Converts a callable or python ty into the most appropriate param43 unmodified linesmodified:click/utils.py+93 added-1 removed
1 import sys2 import codecs3 from collections import deque4 5-from ._compat import text_type5+from ._compat import text_type, open_stream, get_streerror, string_types, PY26 7 8 def unpack_args(args, nargs_spec):9 """Given an iterable of arguments and an iterable of nargs specifications111 unmodified lines121 break122 total_length += new_length123 124 return ''.join(result)125+126+127+class LazyFile(object):128+ """A lazy file works like a regular file but it does not fully open129+ the file but it does perform some basic checks early to see if the130+ filename parameter does make sense. This is useful for safely opening131+ files for writing.132+ """133+134+ def __init__(self, filename, mode='r', encoding=None, errors='strict'):135+ self.name = filename136+ self.mode = mode137+ self.encoding = encoding138+ self.errors = errors139+140+ if filename == '-':141+ self._f, self.should_close = open_stream(filename, mode,142+ encoding, errors)143+ else:144+ if 'r' in mode:145+ # Open and close the file in case we're opening it for146+ # reading so that we can catch at least some errors in147+ # some cases early.148+ open(filename, mode, encoding, errors).close()149+ self._f = None150+ self.should_close = True151+152+ def __getattr__(self, name):153+ return getattr(self.open(), name)154+155+ def __repr__(self):156+ if self._f is not None:157+ return repr(self._f)158+ return '<unopened file %r %s>' % (self.name, self.mode)159+160+ def open(self):161+ """Opens the file if it's not yet open. This call might fail with162+ a :exc:`FileError`. Not handling this error will produce an error163+ that click shows.164+ """165+ if self._f is not None:166+ return self._f167+ try:168+ rv, self.should_close = open_stream(self.name, self.mode,169+ self.encoding,170+ self.errors)171+ except (IOError, OSError) as e:172+ from .exceptions import FileError173+ raise FileError(self.name, hint=get_streerror(e))174+ self._f = rv175+ return rv176+177+ def close(self):178+ """Closes the underlying file, no matter what."""179+ if self._f is not None:180+ self._f.close()181+182+ def close_intelligently(self):183+ """This function only closes the file if it was opened by the lazy184+ file wrapper. For instance this will never close stdin.185+ """186+ if self.should_close:187+ self.close()188+189+ def __enter__(self):190+ return self191+192+ def __exit__(self, exc_type, exc_value, tb):193+ self.close_intelligently()194+195+196+def echo(message=None, file=None):197+ """Prints a message plus a newline to the given file or stdout. On198+ first sight this looks like the print function but it has improved199+ support for handling unicode data that does not fail no matter how200+ badly configured the system is.201+202+ :param message: the message to print203+ :param file: the file to write to (defaults to ``stdout``)204+ """205+ if file is None:206+ file = sys.stdout207+ if message is not None:208+ if not isinstance(message, string_types):209+ message = text_type(message)210+ if message:211+ if PY2 and isinstance(message, text_type):212+ encoding = get_best_encoding(file)213+ message = message.encode(encoding, 'replace')214+ file.write(message)215+ file.write('\n')216+ file.flush()modified:docs/api.rst+6 added-2 removed
29 unmodified lines30 .. autofunction:: pass_obj31 32 .. autofunction:: make_pass_decorator33 34-Helper Functions35-----------------34+Utilities35+---------36 37 .. autofunction:: echo38 39 .. autofunction:: echo_via_pager56 unmodified lines96 97 Exceptions98 ----------99 100+.. autoexception:: ClickException101+102 .. autoexception:: Abort103 104 .. autoexception:: UsageError105 106+.. autoexception:: FileError107+108 Formatting109 ----------110 111 .. autoclass:: HelpFormatter3 unmodified linesmodified:docs/arguments.rst+19 added
93 unmodified lines94 invoke(inout, args=['-', 'hello.txt'], input=['hello'],95 terminate_input=True)96 invoke(inout, args=['hello.txt', '-'])97 98+File Opening Safety99+-------------------100+101+The :class:`FileType` type has one problem it needs to deal with and that102+is to decide when to open a file. The default behavior is to be103+"intelligent" about it. What this means is that it will open stdin/stdout104+and files opened for reading immediately. This will directly give the105+user feedback when a file cannot be opened. But it will only open files106+for writing the first time an IO operation is performed by wrapping the107+file automatically in a special wrapper.108+109+This behavior can be forced by passing ``lazy=True`` or ``lazy=False`` to110+the constructor. If the file is openened lazily it will fail on first IO111+operation by raising an :exc:`FileError`.112+113+Since files opened for writing will typically immediatley empty the file,114+the lazy mode should really only be disabled if the developer is 100% sure115+that this is intended behavior.116+117 Environment Variables118 ---------------------119 120 Like options, arguments can also get values from an environment variable.26 unmodified linesmodified:docs/clickdoctools.py+6 added-6 removed
70 unmodified lines71 return input.readline().rstrip('\r\n')72 73 sys.stdout = output74 sys.stderr = output75- old_visible_prompt_func = click.helpers.visible_prompt_func76- old_hidden_prompt_func = click.helpers.hidden_prompt_func77- click.helpers.visible_prompt_func = visible_input78- click.helpers.hidden_prompt_func = hidden_input75+ old_visible_prompt_func = click.termui.visible_prompt_func76+ old_hidden_prompt_func = click.termui.hidden_prompt_func77+ click.termui.visible_prompt_func = visible_input78+ click.termui.hidden_prompt_func = hidden_input79 80 old_env = {}81 try:82 if env:11 unmodified lines94 else:95 os.environ[key] = value96 sys.stdout = sys.__stdout__97 sys.stderr = sys.__stderr__98- click.helpers.visible_prompt_func = old_visible_prompt_func99- click.helpers.hidden_prompt_func = old_hidden_prompt_func98+ click.termui.visible_prompt_func = old_visible_prompt_func99+ click.termui.hidden_prompt_func = old_hidden_prompt_func100 101 102 @contextlib.contextmanager103 def isolated_filesystem():153 unmodified linesmodified:tests/conftest.py+6 added-6 removed
90 unmodified lines91 sys.stdout.write((prompt or '') + '\n')92 sys.stdout.flush()93 return input.readline().rstrip('\r\n')94 95- old_visible_prompt_func = click.helpers.visible_prompt_func96- old_hidden_prompt_func = click.helpers.hidden_prompt_func97- click.helpers.visible_prompt_func = visible_input98- click.helpers.hidden_prompt_func = hidden_input95+ old_visible_prompt_func = click.termui.visible_prompt_func96+ old_hidden_prompt_func = click.termui.hidden_prompt_func97+ click.termui.visible_prompt_func = visible_input98+ click.termui.hidden_prompt_func = hidden_input99 100 old_env = {}101 try:102 if env:11 unmodified lines114 else:115 os.environ[key] = value116 sys.stdout = old_stdout117 sys.stderr = old_stderr118- click.helpers.visible_prompt_func = old_visible_prompt_func119- click.helpers.hidden_prompt_func = old_hidden_prompt_func118+ click.termui.visible_prompt_func = old_visible_prompt_func119+ click.termui.hidden_prompt_func = old_hidden_prompt_func120 121 def invoke(self, cli, args):122 with self.isolation() as out:123 exception = None34 unmodified lines