diff options
author | Andreas Jaeger <aj@suse.com> | 2020-05-09 16:34:27 +0200 |
---|---|---|
committer | Andreas Jaeger <aj@suse.com> | 2020-05-09 16:42:30 +0200 |
commit | dd5a14177176a8631ff2fdf7643b05b3a62fabe9 (patch) | |
tree | 3b1c2c887f3bb6c50c1e52fb7721f81cb35aed34 /oslo_concurrency/processutils.py | |
parent | c5e0dfedf9a3e5a847a5e01bb81db8ce6e3d042d (diff) | |
download | oslo-concurrency-dd5a14177176a8631ff2fdf7643b05b3a62fabe9.tar.gz |
Remove six usage
Remove the usage of six, the python2-python3 compatibility lib.
Change-Id: I56e479d0749504d65be1cf2b5235d454b0b90a1a
Diffstat (limited to 'oslo_concurrency/processutils.py')
-rw-r--r-- | oslo_concurrency/processutils.py | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py index fc815de..40cadf0 100644 --- a/oslo_concurrency/processutils.py +++ b/oslo_concurrency/processutils.py @@ -32,7 +32,6 @@ from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import strutils from oslo_utils import timeutils -import six from oslo_concurrency._i18n import _ @@ -329,7 +328,7 @@ def execute(*cmd, **kwargs): if kwargs: raise UnknownArgumentError(_('Got unknown keyword args: %r') % kwargs) - if isinstance(log_errors, six.integer_types): + if isinstance(log_errors, int): log_errors = LogErrors(log_errors) if not isinstance(log_errors, LogErrors): raise InvalidArgumentError(_('Got invalid arg log_errors: %r') % @@ -413,16 +412,15 @@ def execute(*cmd, **kwargs): if not ignore_exit_code and _returncode not in check_exit_code: (stdout, stderr) = result - if six.PY3: - stdout = os.fsdecode(stdout) - stderr = os.fsdecode(stderr) + stdout = os.fsdecode(stdout) + stderr = os.fsdecode(stderr) sanitized_stdout = strutils.mask_password(stdout) sanitized_stderr = strutils.mask_password(stderr) raise ProcessExecutionError(exit_code=_returncode, stdout=sanitized_stdout, stderr=sanitized_stderr, cmd=sanitized_cmd) - if six.PY3 and not binary and result is not None: + if not binary and result is not None: (stdout, stderr) = result # Decode from the locale using using the surrogateescape error # handler (decoding cannot fail) @@ -491,7 +489,7 @@ def trycmd(*args, **kwargs): out, err = execute(*args, **kwargs) failed = False except ProcessExecutionError as exn: - out, err = '', six.text_type(exn) + out, err = '', str(exn) failed = True if not failed and discard_warnings and err: @@ -543,12 +541,11 @@ def ssh_execute(ssh, cmd, process_input=None, exit_status = channel.recv_exit_status() - if six.PY3: - # Decode from the locale using using the surrogateescape error handler - # (decoding cannot fail). Decode even if binary is True because - # mask_password() requires Unicode on Python 3 - stdout = os.fsdecode(stdout) - stderr = os.fsdecode(stderr) + # Decode from the locale using using the surrogateescape error handler + # (decoding cannot fail). Decode even if binary is True because + # mask_password() requires Unicode on Python 3 + stdout = os.fsdecode(stdout) + stderr = os.fsdecode(stderr) if sanitize_stdout: stdout = strutils.mask_password(stdout) @@ -570,19 +567,9 @@ def ssh_execute(ssh, cmd, process_input=None, cmd=sanitized_cmd) if binary: - if six.PY2: - # On Python 2, stdout is a bytes string if mask_password() failed - # to decode it, or an Unicode string otherwise. Encode to the - # default encoding (ASCII) because mask_password() decodes from - # the same encoding. - if isinstance(stdout, six.text_type): - stdout = stdout.encode() - if isinstance(stderr, six.text_type): - stderr = stderr.encode() - else: - # fsencode() is the reverse operation of fsdecode() - stdout = os.fsencode(stdout) - stderr = os.fsencode(stderr) + # fsencode() is the reverse operation of fsdecode() + stdout = os.fsencode(stdout) + stderr = os.fsencode(stderr) return (stdout, stderr) |