Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Use shlex.quote for quoting shell arguments" #1543

Merged
merged 1 commit into from Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/click/_compat.py
Expand Up @@ -174,8 +174,6 @@ def seekable(self):
iteritems = lambda x: x.iteritems()
range_type = xrange

from pipes import quote as shlex_quote

def is_bytes(x):
return isinstance(x, (buffer, bytearray))

Expand Down Expand Up @@ -284,8 +282,6 @@ def filename_to_ui(value):
isidentifier = lambda x: x.isidentifier()
iteritems = lambda x: iter(x.items())

from shlex import quote as shlex_quote

def is_bytes(x):
return isinstance(x, (bytes, memoryview, bytearray))

Expand Down
22 changes: 9 additions & 13 deletions src/click/_termui_impl.py
Expand Up @@ -17,7 +17,6 @@
from ._compat import isatty
from ._compat import open_stream
from ._compat import range_type
from ._compat import shlex_quote
from ._compat import strip_ansi
from ._compat import term_len
from ._compat import WIN
Expand Down Expand Up @@ -346,10 +345,7 @@ def pager(generator, color=None):
fd, filename = tempfile.mkstemp()
os.close(fd)
try:
if (
hasattr(os, "system")
and os.system("more {}".format(shlex_quote(filename))) == 0
):
if hasattr(os, "system") and os.system('more "{}"'.format(filename)) == 0:
return _pipepager(generator, "more", color)
return _nullpager(stdout, generator, color)
finally:
Expand Down Expand Up @@ -418,7 +414,7 @@ def _tempfilepager(generator, cmd, color):
with open_stream(filename, "wb")[0] as f:
f.write(text.encode(encoding))
try:
os.system("{} {}".format(shlex_quote(cmd), shlex_quote(filename)))
os.system('{} "{}"'.format(cmd, filename))
finally:
os.unlink(filename)

Expand Down Expand Up @@ -463,9 +459,7 @@ def edit_file(self, filename):
environ = None
try:
c = subprocess.Popen(
"{} {}".format(shlex_quote(editor), shlex_quote(filename)),
env=environ,
shell=True,
'{} "{}"'.format(editor, filename), env=environ, shell=True,
)
exit_code = c.wait()
if exit_code != 0:
Expand Down Expand Up @@ -536,16 +530,18 @@ def _unquote_file(url):
elif WIN:
if locate:
url = _unquote_file(url)
args = "explorer /select,{}".format(shlex_quote(url))
args = 'explorer /select,"{}"'.format(_unquote_file(url.replace('"', "")))
else:
args = 'start {} "" {}'.format("/WAIT" if wait else "", shlex_quote(url))
args = 'start {} "" "{}"'.format(
"/WAIT" if wait else "", url.replace('"', "")
)
return os.system(args)
elif CYGWIN:
if locate:
url = _unquote_file(url)
args = "cygstart {}".format(shlex_quote(os.path.dirname(url)))
args = 'cygstart "{}"'.format(os.path.dirname(url).replace('"', ""))
else:
args = "cygstart {} {}".format("-w" if wait else "", shlex_quote(url))
args = 'cygstart {} "{}"'.format("-w" if wait else "", url.replace('"', ""))
return os.system(args)

try:
Expand Down
1 change: 0 additions & 1 deletion tests/test_imports.py
Expand Up @@ -49,7 +49,6 @@ def tracking_import(module, locals=None, globals=None, fromlist=None,
"fcntl",
"datetime",
"pipes",
"shlex",
}

if WIN:
Expand Down