Skip to content
Myr

Merge pull request #1470 from jwodder/shlex-quote

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

Use shlex.quote for quoting shell arguments

authored by David Lord · committed by GitHub · parents 59a4530, e798f64 · Browse files · 4 files+21 added−15 removed
This commit

State

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

Diff stats

4 files+21 added−15 removed

  • tests:+1 added−1 removed
  • other:+20 added−14 removed

4 files+21 added−15 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_]*$')
98 unmodified lines
269 range_type = range270 isidentifier = lambda x: x.isidentifier()271 iteritems = lambda x: iter(x.items())272273 from shlex import quote as shlex_quote274275 def is_bytes(x):276 return isinstance(x, (bytes, memoryview, bytearray))277278 def _is_binary_reader(stream, default=False):
496 unmodified lines
modified:click/_termui_impl.py+14 added-14 removed
14 unmodified lines
15import sys16import time17import math18import contextlib19from ._compat import _default_text_stdout, range_type, PY2, isatty, \20 open_stream, strip_ansi, term_len, get_best_encoding, WIN, int_types, \21 CYGWIN19from ._compat import _default_text_stdout, range_type, isatty, \20 open_stream, shlex_quote, strip_ansi, term_len, get_best_encoding, WIN, \21 int_types, CYGWIN22from .utils import echo23from .exceptions import ClickException2425
301 unmodified lines
327 import tempfile328 fd, filename = tempfile.mkstemp()329 os.close(fd)330 try:331 if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:331 if hasattr(os, 'system') and os.system("more %s" % shlex_quote(filename)) == 0:332 return _pipepager(generator, 'more', color)333 return _nullpager(stdout, generator, color)334 finally:335 os.unlink(filename)
59 unmodified lines
395 encoding = get_best_encoding(sys.stdout)396 with open_stream(filename, 'wb')[0] as f:397 f.write(text.encode(encoding))398 try:399 os.system(cmd + ' "' + filename + '"')399 os.system("%s %s" % (shlex_quote(cmd), shlex_quote(filename)))400 finally:401 os.unlink(filename)402403
36 unmodified lines
440 environ.update(self.env)441 else:442 environ = None443 try:444 c = subprocess.Popen('%s "%s"' % (editor, filename),445 env=environ, shell=True)444 c = subprocess.Popen(445 "%s %s" % (shlex_quote(editor), shlex_quote(filename)),446 env=environ,447 shell=True448 )449 exit_code = c.wait()450 if exit_code != 0:451 raise ClickException('%s: Editing failed!' % editor)452 except OSError as e:
62 unmodified lines
515 null.close()516 elif WIN:517 if locate:518 url = _unquote_file(url)516 args = 'explorer /select,"%s"' % _unquote_file(517 url.replace('"', ''))519 args = "explorer /select,%s" % (shlex_quote(url),)520 else:519 args = 'start %s "" "%s"' % (520 wait and '/WAIT' or '', url.replace('"', ''))521 args = 'start %s "" %s' % ("/WAIT" if wait else "", shlex_quote(url))522 return os.system(args)523 elif CYGWIN:524 if locate:525 url = _unquote_file(url)525 args = 'cygstart "%s"' % (os.path.dirname(url).replace('"', ''))526 args = "cygstart %s" % (shlex_quote(os.path.dirname(url)),)527 else:527 args = 'cygstart %s "%s"' % (528 wait and '-w' or '', url.replace('"', ''))528 args = "cygstart %s %s" % ("-w" if wait else "", shlex_quote(url))529 return os.system(args)530531 try:532 if locate:
106 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+2 added
53 unmodified lines
54- Option help text that is wrapped adds an extra newline at the end to55 distinguish it from the next option. :issue:`1075`56- Consider ``sensible-editor`` when determining the editor to use for57 ``click.edit()``. :pr:`1469`58- Arguments to system calls such as the executable path passed to59 ``click.edit`` can contains spaces. :pr:`1470`606162Version 7.063-----------
540 unmodified lines