Remove usage of six

With python3.x, classes can use 'metaclass=' instead of
'six.add_metaclass', 'six.iteritems' and 'six.iterkeys' can
be replaced by 'items' and 'keys', 'six.moves.urllib.parse'
can be replaced by 'urllib.parse', 'six.StringIO' and
'six.moves.cStringIO' can be replaced by 'io.StringIO',
'six.text_type' and 'six.string_type' are just 'str'.

Change-Id: I84848c0bf8ab3c36dd821141191e2725e4e3b58b
changes/01/756201/2
songwenping 2 years ago committed by root
parent 098a3fe2de
commit c2df9215e1
  1. 1
      doc/source/contributor/developing.rst
  2. 1
      lower-constraints.txt
  3. 2
      openstackclient/api/object_store_v1.py
  4. 4
      openstackclient/common/sdk_utils.py
  5. 5
      openstackclient/compute/v2/server.py
  6. 3
      openstackclient/identity/v3/access_rule.py
  7. 22
      openstackclient/network/common.py
  8. 8
      openstackclient/shell.py
  9. 15
      openstackclient/tests/unit/compute/v2/test_server.py
  10. 5
      openstackclient/tests/unit/compute/v2/test_service.py
  11. 3
      openstackclient/tests/unit/fakes.py
  12. 3
      openstackclient/tests/unit/object/v1/fakes.py
  13. 6
      openstackclient/tests/unit/object/v1/test_object_all.py
  14. 2
      openstackclient/tests/unit/utils.py
  15. 1
      requirements.txt

@ -203,7 +203,6 @@ Example
from osc_lib.api import auth
from osc_lib import utils
import six
from openstackclient import shell
from openstackclient.tests import utils

@ -119,7 +119,6 @@ rfc3986==0.3.1
Routes==2.3.1
rsd-lib==0.1.0
simplejson==3.5.1
six==1.10.0
smmap==0.9.0
statsd==3.2.1
stestr==1.0.0

@ -17,9 +17,9 @@ import io
import logging
import os
import sys
import urllib
from osc_lib import utils
from six.moves import urllib
from openstackclient.api import api

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
def get_osc_show_columns_for_sdk_resource(
sdk_resource,
@ -44,7 +42,7 @@ def get_osc_show_columns_for_sdk_resource(
for col_name in invisible_columns:
if col_name in display_columns:
display_columns.remove(col_name)
for sdk_attr, osc_attr in six.iteritems(osc_column_map):
for sdk_attr, osc_attr in osc_column_map.items():
if sdk_attr in display_columns:
attr_map[osc_attr] = sdk_attr
display_columns.remove(sdk_attr)

@ -30,7 +30,6 @@ from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
from oslo_utils import timeutils
import six
from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
@ -97,7 +96,7 @@ def _get_ip_address(addresses, address_type, ip_address_family):
for network in addresses:
for addy in addresses[network]:
# Case where it is list of strings
if isinstance(addy, six.string_types):
if isinstance(addy, str):
if new_address_type == 'fixed':
return addresses[network][0]
else:
@ -876,7 +875,7 @@ class CreateServer(command.ShowOne):
boot_args = [parsed_args.server_name, image, flavor]
# Handle block device by device name order, like: vdb -> vdc -> vdd
for dev_name in sorted(six.iterkeys(parsed_args.block_device_mapping)):
for dev_name in sorted(parsed_args.block_device_mapping):
dev_map = parsed_args.block_device_mapping[dev_name]
dev_map = dev_map.split(':')
if dev_map[0]:

@ -20,7 +20,6 @@ import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
from openstackclient.identity import common
@ -115,4 +114,4 @@ class ShowAccessRule(command.ShowOne):
access_rule._info.pop('links', None)
return zip(*sorted(six.iteritems(access_rule._info)))
return zip(*sorted(access_rule._info.items()))

@ -18,7 +18,6 @@ import logging
import openstack.exceptions
from osc_lib.command import command
from osc_lib import exceptions
import six
from openstackclient.i18n import _
@ -54,8 +53,7 @@ def check_missing_extension_if_error(client_manager, attrs):
raise
@six.add_metaclass(abc.ABCMeta)
class NetDetectionMixin(object):
class NetDetectionMixin(metaclass=abc.ABCMeta):
"""Convenience methods for nova-network vs. neutron decisions.
A live environment detects which network type it is running and creates its
@ -166,8 +164,8 @@ class NetDetectionMixin(object):
pass
@six.add_metaclass(abc.ABCMeta)
class NetworkAndComputeCommand(NetDetectionMixin, command.Command):
class NetworkAndComputeCommand(NetDetectionMixin, command.Command,
metaclass=abc.ABCMeta):
"""Network and Compute Command
Command class for commands that support implementation via
@ -178,8 +176,8 @@ class NetworkAndComputeCommand(NetDetectionMixin, command.Command):
pass
@six.add_metaclass(abc.ABCMeta)
class NetworkAndComputeDelete(NetworkAndComputeCommand):
class NetworkAndComputeDelete(NetworkAndComputeCommand,
metaclass=abc.ABCMeta):
"""Network and Compute Delete
Delete class for commands that support implementation via
@ -222,8 +220,8 @@ class NetworkAndComputeDelete(NetworkAndComputeCommand):
raise exceptions.CommandError(msg)
@six.add_metaclass(abc.ABCMeta)
class NetworkAndComputeLister(NetDetectionMixin, command.Lister):
class NetworkAndComputeLister(NetDetectionMixin, command.Lister,
metaclass=abc.ABCMeta):
"""Network and Compute Lister
Lister class for commands that support implementation via
@ -234,8 +232,8 @@ class NetworkAndComputeLister(NetDetectionMixin, command.Lister):
pass
@six.add_metaclass(abc.ABCMeta)
class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne):
class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne,
metaclass=abc.ABCMeta):
"""Network and Compute ShowOne
ShowOne class for commands that support implementation via
@ -255,5 +253,5 @@ class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne):
except openstack.exceptions.HttpException as exc:
msg = _("Error while executing command: %s") % exc.message
if exc.details:
msg += ", " + six.text_type(exc.details)
msg += ", " + str(exc.details)
raise exceptions.CommandError(msg)

@ -16,13 +16,11 @@
"""Command-line interface to the OpenStack APIs"""
import locale
import sys
from osc_lib.api import auth
from osc_lib.command import commandmanager
from osc_lib import shell
import six
import openstackclient
from openstackclient.common import clientmanager
@ -143,12 +141,6 @@ class OpenStackShell(shell.OpenStackShell):
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
if six.PY2:
# Emulate Py3, decode argv into Unicode based on locale so that
# commands always see arguments as text instead of binary data
encoding = locale.getpreferredencoding()
if encoding:
argv = map(lambda arg: arg.decode(encoding), argv)
return OpenStackShell().run(argv)

@ -24,7 +24,6 @@ from openstack import exceptions as sdk_exceptions
from osc_lib import exceptions
from osc_lib import utils as common_utils
from oslo_utils import timeutils
import six
from openstackclient.compute.v2 import server
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@ -1907,7 +1906,7 @@ class TestServerCreate(TestServer):
self.cmd.take_action, parsed_args)
# Assert it is the error we expect.
self.assertIn('--volume is not allowed with --boot-from-volume',
six.text_type(ex))
str(ex))
def test_server_create_image_property(self):
arglist = [
@ -3288,7 +3287,7 @@ class TestServerMigrate(TestServer):
# Make sure it's the error we expect.
self.assertIn('--os-compute-api-version 2.56 or greater is required '
'to use --host without --live-migration.',
six.text_type(ex))
str(ex))
self.servers_mock.get.assert_called_with(self.server.id)
self.assertNotCalled(self.servers_mock.live_migrate)
@ -3323,7 +3322,7 @@ class TestServerMigrate(TestServer):
# A warning should have been logged for using --live.
mock_warning.assert_called_once()
self.assertIn('The --live option has been deprecated.',
six.text_type(mock_warning.call_args[0][0]))
str(mock_warning.call_args[0][0]))
def test_server_live_migrate_host_pre_2_30(self):
# Tests that the --host option is not supported for --live-migration
@ -3346,7 +3345,7 @@ class TestServerMigrate(TestServer):
# Make sure it's the error we expect.
self.assertIn('--os-compute-api-version 2.30 or greater is required '
'when using --host', six.text_type(ex))
'when using --host', str(ex))
self.servers_mock.get.assert_called_with(self.server.id)
self.assertNotCalled(self.servers_mock.live_migrate)
@ -3436,7 +3435,7 @@ class TestServerMigrate(TestServer):
# A warning should have been logged for using --live.
mock_warning.assert_called_once()
self.assertIn('The --live option has been deprecated.',
six.text_type(mock_warning.call_args[0][0]))
str(mock_warning.call_args[0][0]))
def test_server_live_migrate_live_and_host_mutex(self):
# Tests specifying both the --live and --host options which are in a
@ -4352,7 +4351,7 @@ class TestServerResize(TestServer):
# A warning should have been logged for using --confirm.
mock_warning.assert_called_once()
self.assertIn('The --confirm option has been deprecated.',
six.text_type(mock_warning.call_args[0][0]))
str(mock_warning.call_args[0][0]))
def test_server_resize_revert(self):
arglist = [
@ -4377,7 +4376,7 @@ class TestServerResize(TestServer):
# A warning should have been logged for using --revert.
mock_warning.assert_called_once()
self.assertIn('The --revert option has been deprecated.',
six.text_type(mock_warning.call_args[0][0]))
str(mock_warning.call_args[0][0]))
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
def test_server_resize_with_wait_ok(self, mock_wait_for_status):

@ -18,7 +18,6 @@ from unittest.mock import call
from novaclient import api_versions
from osc_lib import exceptions
import six
from openstackclient.compute.v2 import service
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@ -502,7 +501,7 @@ class TestServiceSet(TestService):
self.cmd._find_service_by_host_and_binary,
self.service_mock, 'fake-host', 'nova-compute')
self.assertIn('Compute service for host "fake-host" and binary '
'"nova-compute" not found.', six.text_type(ex))
'"nova-compute" not found.', str(ex))
def test_service_set_find_service_by_host_and_binary_many_results(self):
# Tests that more than one compute service is found by host and binary.
@ -512,4 +511,4 @@ class TestServiceSet(TestService):
self.service_mock, 'fake-host', 'nova-compute')
self.assertIn('Multiple compute services found for host "fake-host" '
'and binary "nova-compute". Unable to proceed.',
six.text_type(ex))
str(ex))

@ -19,7 +19,6 @@ from unittest import mock
from keystoneauth1 import fixture
import requests
import six
AUTH_TOKEN = "foobar"
@ -253,7 +252,7 @@ class FakeResponse(requests.Response):
self.headers.update(headers)
self._content = json.dumps(data)
if not isinstance(self._content, six.binary_type):
if not isinstance(self._content, bytes):
self._content = self._content.encode()

@ -14,7 +14,6 @@
#
from keystoneauth1 import session
import six
from openstackclient.api import object_store_v1 as object_store
from openstackclient.tests.unit import utils
@ -68,7 +67,7 @@ OBJECT = {
'last_modified': object_modified_1,
}
object_1_content = six.b('object 1 content')
object_1_content = b'object 1 content'
OBJECT_2 = {
'name': object_name_2,

@ -12,11 +12,11 @@
#
import copy
import io
from unittest import mock
from osc_lib import exceptions
from requests_mock.contrib import fixture
import six
from openstackclient.object.v1 import object as object_cmds
from openstackclient.tests.unit.object.v1 import fakes as object_fakes
@ -241,9 +241,9 @@ class TestObjectSave(TestObjectAll):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
class FakeStdout(six.BytesIO):
class FakeStdout(io.BytesIO):
def __init__(self):
six.BytesIO.__init__(self)
io.BytesIO.__init__(self)
self.context_manager_calls = []
def __enter__(self):

@ -14,11 +14,11 @@
# under the License.
#
from io import StringIO
import os
from cliff import columns as cliff_columns
import fixtures
from six.moves import StringIO
import testtools
from openstackclient.tests.unit import fakes

@ -2,7 +2,6 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
pbr!=2.1.0,>=2.0.0 # Apache-2.0
six>=1.10.0 # MIT
cliff!=2.9.0,>=2.8.0 # Apache-2.0
openstacksdk>=0.48.0 # Apache-2.0

Loading…
Cancel
Save