Skip to content

Commit

Permalink
Replace deprecated stdlib calls (#1572)
Browse files Browse the repository at this point in the history
* Replace pipes import with shlex for Python 3
* Replace imports of cgi with html for Python 3

Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso authored Nov 10, 2023
1 parent 371644d commit 0137866
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion release-rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import argparse
import os
from datetime import date
from pipes import quote
from rez.utils.py23 import quote
import subprocess
import sys

Expand Down
2 changes: 1 addition & 1 deletion src/rez/bind/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rez.utils.execution import Popen
from rez.utils.logging_ import print_debug
from rez.vendor.six import six
from pipes import quote
from rez.utils.py23 import quote
import subprocess
import os.path
import os
Expand Down
2 changes: 1 addition & 1 deletion src/rez/build_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from rez.config import config
from rez.vendor.enum import Enum
from contextlib import contextmanager
from pipes import quote
from rez.utils.py23 import quote
import getpass
import os.path
import sys
Expand Down
2 changes: 1 addition & 1 deletion src/rez/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rez.utils.logging_ import print_info, print_warning, print_error
from rez.vendor.six import six
from rez.vendor.version.requirement import Requirement, RequirementList
from pipes import quote
from rez.utils.py23 import quote
import time
import sys
import os
Expand Down
2 changes: 1 addition & 1 deletion src/rez/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from rez.config import config

import os
from pipes import quote
from rez.utils.py23 import quote
from pprint import pformat
import re
import shutil
Expand Down
2 changes: 1 addition & 1 deletion src/rez/release_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rez.utils.execution import Popen
from rez.utils.logging_ import print_debug
from rez.utils.filesystem import walk_up_dirs
from pipes import quote
from rez.utils.py23 import quote
import subprocess


Expand Down
4 changes: 2 additions & 2 deletions src/rez/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rez.vendor.six import six
import os
import os.path
import pipes
from rez.utils.py23 import quote


basestring = six.string_types[0]
Expand Down Expand Up @@ -507,7 +507,7 @@ def _create_ex():
try:
p = Popen(cmd, env=env, **Popen_args)
except Exception as e:
cmd_str = ' '.join(map(pipes.quote, cmd))
cmd_str = ' '.join(map(quote, cmd))
raise RezSystemError("Error running command:\n%s\n%s"
% (cmd_str, str(e)))
return p
Expand Down
4 changes: 2 additions & 2 deletions src/rez/utils/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Functions that wrap readelf/patchelf utils on linux.
"""
import os
import pipes
from rez.utils.py23 import quote
import subprocess

from rez.utils.filesystem import make_path_writable
Expand Down Expand Up @@ -64,7 +64,7 @@ def _run(*nargs, **popen_kwargs):
out, err = proc.communicate()

if proc.returncode:
cmd_ = ' '.join(pipes.quote(x) for x in nargs)
cmd_ = ' '.join(quote(x) for x in nargs)

raise RuntimeError(
"Command %s - failed with exitcode %d: %s"
Expand Down
12 changes: 12 additions & 0 deletions src/rez/utils/py23.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@

from rez.vendor.six import six

try:
from html import escape # noqa: F401
except ImportError:
# Python 2
from cgi import escape # noqa: F401

try:
from shlex import quote # noqa: F401
except ImportError:
# Python 2
from pipes import quote # noqa: F401


def get_function_arg_names(func):
"""Get names of a function's args.
Expand Down
5 changes: 2 additions & 3 deletions src/rezgui/widgets/ChangelogEdit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@


from Qt import QtCore, QtWidgets, QtGui
import cgi

import rez.utils.py23

def plaintext_to_html(txt):
out = cgi.escape(txt)
out = rez.utils.py23.escape(txt)
out = out.replace('\t', " ")
out = out.replace(' ', "&nbsp;")
out = out.replace('\n', "<br>")
Expand Down
2 changes: 1 addition & 1 deletion src/rezplugins/build_system/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from builtins import map
except ImportError:
pass
from pipes import quote
from rez.utils.py23 import quote
import functools
import os.path
import sys
Expand Down
4 changes: 2 additions & 2 deletions src/rezplugins/shell/csh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
CSH shell
"""
import pipes
import os.path
import subprocess
import re
Expand All @@ -16,6 +15,7 @@
from rez.utils.platform_ import platform_
from rez.shells import UnixShell
from rez.rex import EscapedString
from rez.utils.py23 import quote


class CSH(UnixShell):
Expand Down Expand Up @@ -105,7 +105,7 @@ def escape_string(self, value, is_path=False):

for is_literal, txt in value.strings:
if is_literal:
txt = pipes.quote(txt)
txt = quote(txt)
if not txt.startswith("'"):
txt = "'%s'" % txt
else:
Expand Down
4 changes: 2 additions & 2 deletions src/rezplugins/shell/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"""
import os
import os.path
import pipes
import subprocess
from rez.config import config
from rez.utils.execution import Popen
from rez.utils.platform_ import platform_
from rez.shells import UnixShell
from rez.rex import EscapedString
from rez.utils.py23 import quote


class SH(UnixShell):
Expand Down Expand Up @@ -126,7 +126,7 @@ def escape_string(self, value, is_path=False):

for is_literal, txt in value.strings:
if is_literal:
txt = pipes.quote(txt)
txt = quote(txt)
if not txt.startswith("'"):
txt = "'%s'" % txt
else:
Expand Down
4 changes: 2 additions & 2 deletions src/rezplugins/shell/tcsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from rezplugins.shell.csh import CSH
from rez import module_root_path
from rez.rex import EscapedString
from rez.utils.py23 import quote
import os.path
import pipes


class TCSH(CSH):
Expand All @@ -26,7 +26,7 @@ def escape_string(self, value, is_path=False):

for is_literal, txt in value.strings:
if is_literal:
txt = pipes.quote(txt)
txt = quote(txt)
if not txt.startswith("'"):
txt = "'%s'" % txt
else:
Expand Down

0 comments on commit 0137866

Please sign in to comment.