commit dd05bdd0cd1eaa1e1fd0695b39c9db7e965a531c Author: zhangbailin Date: Mon Oct 12 14:58:41 2020 +0800 Remove usage of six Remove six-library Replace the following items with Python 3 style code. - six.text_type - six.string_types - six.PY3 - six.StringIO Change-Id: I485985ca673db78b94757753619e2760b06a3ad6 diff --git a/doc/source/contributor/developing.rst b/doc/source/contributor/developing.rst index 00d672f..039ee67 100644 --- a/doc/source/contributor/developing.rst +++ b/doc/source/contributor/developing.rst @@ -167,7 +167,6 @@ Example from osc_lib.api import auth from osc_lib import utils - import six from openstackclient import shell from openstackclient.tests import utils diff --git a/lower-constraints.txt b/lower-constraints.txt index ea03178..869b898 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -52,7 +52,6 @@ requests-mock==1.2.0 requests==2.14.2 requestsexceptions==1.2.0 simplejson==3.5.1 -six==1.10.0 snowballstemmer==1.2.1 Sphinx==2.0.0 sphinxcontrib-websupport==1.0.1 diff --git a/masakariclient/common/utils.py b/masakariclient/common/utils.py index 5f8974b..e300c72 100644 --- a/masakariclient/common/utils.py +++ b/masakariclient/common/utils.py @@ -14,7 +14,6 @@ import os import prettytable -import six import textwrap from oslo_serialization import jsonutils @@ -122,7 +121,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None): if data is None: data = '-' # '\r' would break the table, so remove it. - data = six.text_type(data).replace("\r", "") + data = str(data).replace("\r", "") row.append(data) pt.add_row(row) @@ -131,8 +130,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None): else: result = encodeutils.safe_encode(pt.get_string()) - if six.PY3: - result = result.decode() + result = result.decode() print(result) @@ -147,10 +145,10 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): if isinstance(v, (dict, list)): v = jsonutils.dumps(v) if wrap > 0: - v = textwrap.fill(six.text_type(v), wrap) + v = textwrap.fill(str(v), wrap) # if value has a newline, add in multiple rows # e.g. fault with stacktrace - if v and isinstance(v, six.string_types) and (r'\n' in v or '\r' in v): + if v and isinstance(v, str) and (r'\n' in v or '\r' in v): # '\r' would break the table, so remove it. if '\r' in v: v = v.replace('\r', '') @@ -166,8 +164,7 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): result = encodeutils.safe_encode(pt.get_string()) - if six.PY3: - result = result.decode() + result = result.decode() print(result) diff --git a/masakariclient/shell.py b/masakariclient/shell.py index 0a5fded..b450edd 100644 --- a/masakariclient/shell.py +++ b/masakariclient/shell.py @@ -17,7 +17,6 @@ import logging import sys from oslo_utils import encodeutils -import six import masakariclient from masakariclient import cliargs @@ -199,7 +198,7 @@ def main(args=None): if '--debug' in args or '-d' in args: raise else: - print(encodeutils.safe_encode(six.text_type(e)), sys.stderr) + print(encodeutils.safe_encode(str(e), sys.stderr)) return 1 diff --git a/masakariclient/tests/unit/test_shell.py b/masakariclient/tests/unit/test_shell.py index 7e0248e..c9cfdfc 100644 --- a/masakariclient/tests/unit/test_shell.py +++ b/masakariclient/tests/unit/test_shell.py @@ -18,10 +18,10 @@ test_shell Tests for `masakariclient` module. """ +import io import logging from unittest import mock -import six import sys import testtools @@ -61,7 +61,7 @@ class TestMasakariShell(base.TestCase): def _shell(self, func, *args, **kwargs): orig_out = sys.stdout - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() func(*args, **kwargs) output = sys.stdout.getvalue() sys.stdout.close() diff --git a/masakariclient/tests/unit/v1/test_shell.py b/masakariclient/tests/unit/v1/test_shell.py index 2a83a8e..58b2258 100644 --- a/masakariclient/tests/unit/v1/test_shell.py +++ b/masakariclient/tests/unit/v1/test_shell.py @@ -21,7 +21,7 @@ Tests for `masakariclient` module. from unittest import mock import ddt -import six +import io import sys from openstack import exceptions as sdk_exc @@ -231,7 +231,7 @@ class TestV1Shell(base.TestCase): args = mock.Mock() original = sys.stdout - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() ms.do_segment_delete(service, args) output = sys.stdout.getvalue() sys.stdout = original @@ -364,7 +364,7 @@ class TestV1Shell(base.TestCase): args = mock.Mock() original = sys.stdout - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() ms.do_host_delete(service, args) output = sys.stdout.getvalue() sys.stdout = original