Use shlex.quote instead of deprecated pipes.quote (#2351)

This commit is contained in:
Lumír 'Frenzy' Balhar 2022-06-07 12:07:19 +02:00 committed by Bernát Gábor
parent 784163eb47
commit 0bf46eb638
No known key found for this signature in database
GPG key ID: 389A324926656E0D
6 changed files with 34 additions and 12 deletions

View file

@ -0,0 +1 @@
Use ``shlex.quote`` instead of deprecated ``pipes.quote`` in Python 3. - by :user:`frenzymadness`.

View file

@ -8,7 +8,6 @@ from __future__ import absolute_import, unicode_literals
import logging
import os
import pipes
import sys
from collections import OrderedDict
@ -19,6 +18,11 @@ from virtualenv.util.path import Path
from virtualenv.util.six import ensure_text
from virtualenv.util.subprocess import Popen, subprocess
if PY2:
from pipes import quote
else:
from shlex import quote
_CACHE = OrderedDict()
_CACHE[Path(sys.executable)] = PythonInfo()
@ -126,7 +130,7 @@ class LogCmd(object):
def e(v):
return v.decode("utf-8") if isinstance(v, bytes) else v
cmd_repr = e(" ").join(pipes.quote(e(c)) for c in self.cmd)
cmd_repr = e(" ").join(quote(e(c)) for c in self.cmd)
if self.env is not None:
cmd_repr += e(" env of {!r}").format(self.env)
if PY2:

View file

@ -3,7 +3,6 @@ import argparse
import io
import json
import os
import pipes
import shutil
import subprocess
import sys
@ -18,6 +17,11 @@ from tempfile import TemporaryDirectory
from packaging.markers import Marker
from packaging.requirements import Requirement
if sys.version_info[0] == 2:
from pipes import quote
else:
from shlex import quote
HERE = Path(__file__).parent.absolute()
VERSIONS = ["3.{}".format(i) for i in range(10, 4, -1)] + ["2.7"]
@ -227,7 +231,7 @@ def run_suppress_output(cmd, stop_print_on_fail=False):
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
out, err = process.communicate()
if stop_print_on_fail and process.returncode != 0:
print("exit with {} of {}".format(process.returncode, " ".join(pipes.quote(i) for i in cmd)), file=sys.stdout)
print("exit with {} of {}".format(process.returncode, " ".join(quote(i) for i in cmd)), file=sys.stdout)
if out:
print(out, file=sys.stdout)
if err:

View file

@ -1,7 +1,6 @@
from __future__ import absolute_import, unicode_literals
import os
import pipes
import re
import shutil
import subprocess
@ -11,12 +10,17 @@ from os.path import dirname, normcase
import pytest
import six
from virtualenv.info import IS_PYPY, WIN_CPYTHON_2
from virtualenv.info import IS_PYPY, PY2, WIN_CPYTHON_2
from virtualenv.run import cli_run
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_str, ensure_text
from virtualenv.util.subprocess import Popen
if PY2:
from pipes import quote
else:
from shlex import quote
class ActivationTester(object):
def __init__(self, of_class, session, cmd, activate_script, extension):
@ -157,7 +161,7 @@ class ActivationTester(object):
assert out[-1] == "None", raw
def quote(self, s):
return pipes.quote(s)
return quote(s)
def python_cmd(self, cmd):
return "{} -c {}".format(os.path.basename(sys.executable), self.quote(cmd))

View file

@ -1,8 +1,12 @@
from __future__ import absolute_import, unicode_literals
import pipes
from virtualenv.activation import BatchActivator
from virtualenv.info import PY2
if PY2:
from pipes import quote
else:
from shlex import quote
def test_batch(activation_tester_class, activation_tester, tmp_path, activation_python):
@ -25,7 +29,7 @@ def test_batch(activation_tester_class, activation_tester, tmp_path, activation_
def quote(self, s):
"""double quotes needs to be single, and single need to be double"""
return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in pipes.quote(s))
return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in quote(s))
def print_prompt(self):
return "echo %PROMPT%"

View file

@ -1,11 +1,16 @@
from __future__ import absolute_import, unicode_literals
import pipes
import sys
import pytest
from virtualenv.activation import PowerShellActivator
from virtualenv.info import PY2
if PY2:
from pipes import quote
else:
from shlex import quote
@pytest.mark.slow
@ -23,7 +28,7 @@ def test_powershell(activation_tester_class, activation_tester, monkeypatch):
def quote(self, s):
"""powershell double double quote needed for quotes within single quotes"""
return pipes.quote(s).replace('"', '""')
return quote(s).replace('"', '""')
def _get_test_lines(self, activate_script):
# for BATCH utf-8 support need change the character code page to 650001