Skip to content
Myr

Merge branch '7.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 289913b, 37d8970 · Browse files · 9 files+43 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+43 added−23 removed

  • tests:+1 added−1 removed
  • other:+42 added−22 removed

9 files+43 added−23 removed

modified:click/_compat.py+4 added
160 unmodified lines
161 int_types = (int, long)162 iteritems = lambda x: x.iteritems()163 range_type = xrange164165 from pipes import quote as shlex_quote166167 def is_bytes(x):168 return isinstance(x, (buffer, bytearray))169170 _identifier_re = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
97 unmodified lines
268 range_type = range269 isidentifier = lambda x: x.isidentifier()270 iteritems = lambda x: iter(x.items())271272 from shlex import quote as shlex_quote273274 def is_bytes(x):275 return isinstance(x, (bytes, memoryview, bytearray))276277 def _is_binary_reader(stream, default=False):
496 unmodified lines
modified:click/_termui_impl.py+13 added-13 removed
15 unmodified lines
16import time17import math18import contextlib19from ._compat import _default_text_stdout, range_type, isatty, \20 open_stream, strip_ansi, term_len, get_best_encoding, WIN, int_types, \21 CYGWIN20 open_stream, shlex_quote, strip_ansi, term_len, get_best_encoding, WIN, \21 int_types, CYGWIN22from .utils import echo23from .exceptions import ClickException2425
314 unmodified lines
340 import tempfile341 fd, filename = tempfile.mkstemp()342 os.close(fd)343 try:344 if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:344 if hasattr(os, 'system') and os.system("more %s" % shlex_quote(filename)) == 0:345 return _pipepager(generator, 'more', color)346 return _nullpager(stdout, generator, color)347 finally:348 os.unlink(filename)
59 unmodified lines
408 encoding = get_best_encoding(sys.stdout)409 with open_stream(filename, 'wb')[0] as f:410 f.write(text.encode(encoding))411 try:412 os.system(cmd + ' "' + filename + '"')412 os.system("%s %s" % (shlex_quote(cmd), shlex_quote(filename)))413 finally:414 os.unlink(filename)415416
36 unmodified lines
453 environ.update(self.env)454 else:455 environ = None456 try:457 c = subprocess.Popen('%s "%s"' % (editor, filename),458 env=environ, shell=True)457 c = subprocess.Popen(458 "%s %s" % (shlex_quote(editor), shlex_quote(filename)),459 env=environ,460 shell=True461 )462 exit_code = c.wait()463 if exit_code != 0:464 raise ClickException('%s: Editing failed!' % editor)465 except OSError as e:
68 unmodified lines
534 null.close()535 elif WIN:536 if locate:537 url = _unquote_file(url)535 args = 'explorer /select,"%s"' % _unquote_file(536 url.replace('"', ''))538 args = "explorer /select,%s" % (shlex_quote(url),)539 else:538 args = 'start %s "" "%s"' % (539 wait and '/WAIT' or '', url.replace('"', ''))540 args = 'start %s "" %s' % ("/WAIT" if wait else "", shlex_quote(url))541 return os.system(args)542 elif CYGWIN:543 if locate:544 url = _unquote_file(url)544 args = 'cygstart "%s"' % (os.path.dirname(url).replace('"', ''))545 args = "cygstart %s" % (shlex_quote(os.path.dirname(url)),)546 else:546 args = 'cygstart %s "%s"' % (547 wait and '-w' or '', url.replace('"', ''))547 args = "cygstart %s %s" % ("-w" if wait else "", shlex_quote(url))548 return os.system(args)549550 try:551 if locate:
106 unmodified lines
modified:click/_winconsole.py+11 added-2 removed
15 unmodified lines
16import ctypes17import msvcrt18from ._compat import _NonClosingTextIOWrapper, text_type, PY219from ctypes import byref, POINTER, c_int, c_char, c_char_p, \20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE, \21 WinError22try:23 from ctypes import pythonapi24 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer25 PyBuffer_Release = pythonapi.PyBuffer_Release
14 unmodified lines
40 ('GetCommandLineW', windll.kernel32))41CommandLineToArgvW = WINFUNCTYPE(42 POINTER(LPWSTR), LPCWSTR, POINTER(c_int))(43 ('CommandLineToArgvW', windll.shell32))44LocalFree = WINFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p)(45 ('LocalFree', windll.kernel32))464748STDIN_HANDLE = GetStdHandle(-10)49STDOUT_HANDLE = GetStdHandle(-11)
218 unmodified lines
268269 def _get_windows_argv():270 argc = c_int(0)271 argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))272 if not argv_unicode:273 raise WinError()274 try:269 argv = [argv_unicode[i] for i in range(0, argc.value)]275 argv = [argv_unicode[i] for i in range(0, argc.value)]276 finally:277 LocalFree(argv_unicode)278 del argv_unicode279280 if not hasattr(sys, 'frozen'):281 argv = argv[1:]282 while len(argv) > 0:
48 unmodified lines
modified:docs/bashcomplete.rst+4 added-4 removed
16 unmodified lines
1718What it Completes19-----------------2021Generally, the Bash completion support will complete subcommands, options22and any option or argument values where the type is click.Choice.23Subcommands and choices are always listed whereas options only if at24least a dash has been provided. Example::21Generally, the Bash completion support will complete subcommands,22options, and any option or argument values where the type is23:class:`click.Choice`. Subcommands and choices are always listed whereas24options are only listed if at least a dash has been provided. ::2526 $ repo <TAB><TAB>27 clone commit copy delete setuser28 $ repo clone -<TAB><TAB>
103 unmodified lines
modified:docs/options.rst+2 added
143 unmodified lines
144 @click.option('--item', nargs=2, type=click.Tuple([str, int]))145 def putitem(item):146 click.echo('name=%s id=%d' % item)147148.. _multiple-options:149150Multiple Options151----------------152153Similarly to ``nargs``, there is also the case of wanting to support a
675 unmodified lines
modified:docs/parameters.rst+2 added-1 removed
26 unmodified lines
27 might be too specific to be automatically documented)2829On the other hand arguments, unlike options, can accept an arbitrary number30of arguments. Options can strictly ever only accept a fixed number of31arguments (defaults to 1).31arguments (defaults to 1), or they may be specified multiple times using32:ref:`multiple-options`.3334Parameter Types35---------------36
114 unmodified lines
modified:docs/utils.rst+2 added-2 removed
31 unmodified lines
3233Last but not least :func:`echo` uses click's intelligent internal output34streams to stdout and stderr which support unicode output on the Windows35console. This means for as long as you are using `click.echo` you can36output unicode character (there are some limitations on the default font36output unicode characters (there are some limitations on the default font37with regards to which characters can be displayed). This functionality is38new in Click 6.0.3940.. versionadded:: 6.0
169 unmodified lines
210Click supports launching editors automatically through :func:`edit`. This211is very useful for asking users for multi-line input. It will212automatically open the user's defined editor or fall back to a sensible213default. If the user closes the editor without saving, the return value214will be `None` otherwise the entered text.214will be ``None``, otherwise the entered text.215216Example usage::217218 import click
202 unmodified lines
modified:tests/test_imports.py+1 added-1 removed
30 unmodified lines
3132ALLOWED_IMPORTS = set([33 'weakref', 'os', 'struct', 'collections', 'sys', 'contextlib',34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',35 'threading', 'colorama', 'errno', 'fcntl', 'datetime'35 'threading', 'colorama', 'errno', 'fcntl', 'datetime', 'pipes', 'shlex'36])3738if WIN:39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt', 'time',
16 unmodified lines
modified:CHANGES.rst+4 added
31 unmodified lines
32- Fix output on Windows Python 2.7 built with MSVC 14. :pr:`1342`33- Fix ``OSError`` when running in MSYS2. :issue:`1338`34- Fix ``OSError`` when redirecting to ``NUL`` stream on Windows.35 :issue:`1065`36- Fix memory leak when parsing Unicode arguments on Windows.37 :issue:`1136`38- Fix error in new AppEngine environments. :issue:`1462`39- Always return one of the passed choices for ``click.Choice``40 :issue:`1277`, :pr:`1318`41- Add ``no_args_is_help`` option to ``click.Command``, defaults to
27 unmodified lines
69- Option help text that is wrapped adds an extra newline at the end to70 distinguish it from the next option. :issue:`1075`71- Consider ``sensible-editor`` when determining the editor to use for72 ``click.edit()``. :pr:`1469`73- Arguments to system calls such as the executable path passed to74 ``click.edit`` can contains spaces. :pr:`1470`757677Version 7.078-----------
541 unmodified lines