ansible-test: prefer shlex.quote (#56823)

This commit is contained in:
Martin Krizek 2019-05-24 22:10:33 +02:00 committed by GitHub
commit 484c023316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View file

@ -9,7 +9,6 @@ import fcntl
import inspect
import json
import os
import pipes
import pkgutil
import random
import re
@ -38,6 +37,11 @@ except ImportError:
# noinspection PyCompatibility
from configparser import ConfigParser
try:
from shlex import quote as cmd_quote
except ImportError:
from pipes import quote as cmd_quote
DOCKER_COMPLETION = {} # type: dict[str, dict[str, str]]
REMOTE_COMPLETION = {} # type: dict[str, dict[str, str]]
PYTHON_PATHS = {} # type: dict[str, str]
@ -389,7 +393,7 @@ def raw_command(cmd, capture=False, env=None, data=None, cwd=None, explain=False
cmd = list(cmd)
escaped_cmd = ' '.join(pipes.quote(c) for c in cmd)
escaped_cmd = ' '.join(cmd_quote(c) for c in cmd)
display.info('Run command: %s' % escaped_cmd, verbosity=cmd_verbosity, truncate=True)
display.info('Working directory: %s' % cwd, verbosity=2)
@ -763,7 +767,7 @@ class SubprocessError(ApplicationError):
:type stderr: str | None
:type runtime: float | None
"""
message = 'Command "%s" returned exit status %s.\n' % (' '.join(pipes.quote(c) for c in cmd), status)
message = 'Command "%s" returned exit status %s.\n' % (' '.join(cmd_quote(c) for c in cmd), status)
if stderr:
message += '>>> Standard Error\n'