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
Provenance
- Commit
c6ef735- Tree
f569e4f- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
289913b- Parent 2
37d8970
9 files changed+43 added−23 removed
modified:click/_compat.py+4 added
160 unmodified lines161 int_types = (int, long)162 iteritems = lambda x: x.iteritems()163 range_type = xrange164 165+ from pipes import quote as shlex_quote166+167 def is_bytes(x):168 return isinstance(x, (buffer, bytearray))169 170 _identifier_re = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')97 unmodified lines268 range_type = range269 isidentifier = lambda x: x.isidentifier()270 iteritems = lambda x: iter(x.items())271 272+ from shlex import quote as shlex_quote273+274 def is_bytes(x):275 return isinstance(x, (bytes, memoryview, bytearray))276 277 def _is_binary_reader(stream, default=False):496 unmodified linesmodified:click/_termui_impl.py+13 added-13 removed
15 unmodified lines16 import time17 import math18 import contextlib19 from ._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, CYGWIN22 from .utils import echo23 from .exceptions import ClickException24 25 314 unmodified lines340 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 lines408 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)415 416 36 unmodified lines453 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 lines534 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)549 550 try:551 if locate:106 unmodified linesmodified:click/_winconsole.py+11 added-2 removed
15 unmodified lines16 import ctypes17 import msvcrt18 from ._compat import _NonClosingTextIOWrapper, text_type, PY219 from 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+ WinError22 try:23 from ctypes import pythonapi24 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer25 PyBuffer_Release = pythonapi.PyBuffer_Release14 unmodified lines40 ('GetCommandLineW', windll.kernel32))41 CommandLineToArgvW = WINFUNCTYPE(42 POINTER(LPWSTR), LPCWSTR, POINTER(c_int))(43 ('CommandLineToArgvW', windll.shell32))44+LocalFree = WINFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p)(45+ ('LocalFree', windll.kernel32))46 47 48 STDIN_HANDLE = GetStdHandle(-10)49 STDOUT_HANDLE = GetStdHandle(-11)218 unmodified lines268 269 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_unicode279 280 if not hasattr(sys, 'frozen'):281 argv = argv[1:]282 while len(argv) > 0:48 unmodified linesmodified:docs/bashcomplete.rst+4 added-4 removed
16 unmodified lines17 18 What it Completes19 -----------------20 21-Generally, the Bash completion support will complete subcommands, options22-and any option or argument values where the type is click.Choice.23-Subcommands and choices are always listed whereas options only if at24-least a dash has been provided. Example::21+Generally, the Bash completion support will complete subcommands,22+options, and any option or argument values where the type is23+:class:`click.Choice`. Subcommands and choices are always listed whereas24+options are only listed if at least a dash has been provided. ::25 26 $ repo <TAB><TAB>27 clone commit copy delete setuser28 $ repo clone -<TAB><TAB>103 unmodified linesmodified:docs/options.rst+2 added
143 unmodified lines144 @click.option('--item', nargs=2, type=click.Tuple([str, int]))145 def putitem(item):146 click.echo('name=%s id=%d' % item)147 148+.. _multiple-options:149+150 Multiple Options151 ----------------152 153 Similarly to ``nargs``, there is also the case of wanting to support a675 unmodified linesmodified:docs/parameters.rst+2 added-1 removed
26 unmodified lines27 might be too specific to be automatically documented)28 29 On the other hand arguments, unlike options, can accept an arbitrary number30 of arguments. Options can strictly ever only accept a fixed number of31-arguments (defaults to 1).31+arguments (defaults to 1), or they may be specified multiple times using32+:ref:`multiple-options`.33 34 Parameter Types35 ---------------36 114 unmodified linesmodified:docs/utils.rst+2 added-2 removed
31 unmodified lines32 33 Last but not least :func:`echo` uses click's intelligent internal output34 streams to stdout and stderr which support unicode output on the Windows35 console. This means for as long as you are using `click.echo` you can36-output unicode character (there are some limitations on the default font36+output unicode characters (there are some limitations on the default font37 with regards to which characters can be displayed). This functionality is38 new in Click 6.0.39 40 .. versionadded:: 6.0169 unmodified lines210 Click supports launching editors automatically through :func:`edit`. This211 is very useful for asking users for multi-line input. It will212 automatically open the user's defined editor or fall back to a sensible213 default. If the user closes the editor without saving, the return value214-will be `None` otherwise the entered text.214+will be ``None``, otherwise the entered text.215 216 Example usage::217 218 import click202 unmodified linesmodified:tests/test_imports.py+1 added-1 removed
30 unmodified lines31 32 ALLOWED_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 ])37 38 if WIN:39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt', 'time',16 unmodified linesmodified:CHANGES.rst+4 added
31 unmodified lines32 - 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 to27 unmodified lines69 - 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`75 76 77 Version 7.078 -----------541 unmodified lines