Skip to content

Commit c2df921

Browse files
committed
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
1 parent 098a3fe commit c2df921

15 files changed

Lines changed: 30 additions & 51 deletions

File tree

doc/source/contributor/developing.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ Example
203203
204204
from osc_lib.api import auth
205205
from osc_lib import utils
206-
import six
207206
208207
from openstackclient import shell
209208
from openstackclient.tests import utils

lower-constraints.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ rfc3986==0.3.1
119119
Routes==2.3.1
120120
rsd-lib==0.1.0
121121
simplejson==3.5.1
122-
six==1.10.0
123122
smmap==0.9.0
124123
statsd==3.2.1
125124
stestr==1.0.0

openstackclient/api/object_store_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import logging
1818
import os
1919
import sys
20+
import urllib
2021

2122
from osc_lib import utils
22-
from six.moves import urllib
2323

2424
from openstackclient.api import api
2525

openstackclient/common/sdk_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import six
14-
1513

1614
def get_osc_show_columns_for_sdk_resource(
1715
sdk_resource,
@@ -44,7 +42,7 @@ def get_osc_show_columns_for_sdk_resource(
4442
for col_name in invisible_columns:
4543
if col_name in display_columns:
4644
display_columns.remove(col_name)
47-
for sdk_attr, osc_attr in six.iteritems(osc_column_map):
45+
for sdk_attr, osc_attr in osc_column_map.items():
4846
if sdk_attr in display_columns:
4947
attr_map[osc_attr] = sdk_attr
5048
display_columns.remove(sdk_attr)

openstackclient/compute/v2/server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from osc_lib import exceptions
3131
from osc_lib import utils
3232
from oslo_utils import timeutils
33-
import six
3433

3534
from openstackclient.i18n import _
3635
from openstackclient.identity import common as identity_common
@@ -97,7 +96,7 @@ def _get_ip_address(addresses, address_type, ip_address_family):
9796
for network in addresses:
9897
for addy in addresses[network]:
9998
# Case where it is list of strings
100-
if isinstance(addy, six.string_types):
99+
if isinstance(addy, str):
101100
if new_address_type == 'fixed':
102101
return addresses[network][0]
103102
else:
@@ -876,7 +875,7 @@ def _match_image(image_api, wanted_properties):
876875
boot_args = [parsed_args.server_name, image, flavor]
877876

878877
# Handle block device by device name order, like: vdb -> vdc -> vdd
879-
for dev_name in sorted(six.iterkeys(parsed_args.block_device_mapping)):
878+
for dev_name in sorted(parsed_args.block_device_mapping):
880879
dev_map = parsed_args.block_device_mapping[dev_name]
881880
dev_map = dev_map.split(':')
882881
if dev_map[0]:

openstackclient/identity/v3/access_rule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from osc_lib.command import command
2121
from osc_lib import exceptions
2222
from osc_lib import utils
23-
import six
2423

2524
from openstackclient.i18n import _
2625
from openstackclient.identity import common
@@ -115,4 +114,4 @@ def take_action(self, parsed_args):
115114

116115
access_rule._info.pop('links', None)
117116

118-
return zip(*sorted(six.iteritems(access_rule._info)))
117+
return zip(*sorted(access_rule._info.items()))

openstackclient/network/common.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import openstack.exceptions
1919
from osc_lib.command import command
2020
from osc_lib import exceptions
21-
import six
2221

2322
from openstackclient.i18n import _
2423

@@ -54,8 +53,7 @@ def check_missing_extension_if_error(client_manager, attrs):
5453
raise
5554

5655

57-
@six.add_metaclass(abc.ABCMeta)
58-
class NetDetectionMixin(object):
56+
class NetDetectionMixin(metaclass=abc.ABCMeta):
5957
"""Convenience methods for nova-network vs. neutron decisions.
6058
6159
A live environment detects which network type it is running and creates its
@@ -166,8 +164,8 @@ def take_action_compute(self, client, parsed_args):
166164
pass
167165

168166

169-
@six.add_metaclass(abc.ABCMeta)
170-
class NetworkAndComputeCommand(NetDetectionMixin, command.Command):
167+
class NetworkAndComputeCommand(NetDetectionMixin, command.Command,
168+
metaclass=abc.ABCMeta):
171169
"""Network and Compute Command
172170
173171
Command class for commands that support implementation via
@@ -178,8 +176,8 @@ class NetworkAndComputeCommand(NetDetectionMixin, command.Command):
178176
pass
179177

180178

181-
@six.add_metaclass(abc.ABCMeta)
182-
class NetworkAndComputeDelete(NetworkAndComputeCommand):
179+
class NetworkAndComputeDelete(NetworkAndComputeCommand,
180+
metaclass=abc.ABCMeta):
183181
"""Network and Compute Delete
184182
185183
Delete class for commands that support implementation via
@@ -222,8 +220,8 @@ def take_action(self, parsed_args):
222220
raise exceptions.CommandError(msg)
223221

224222

225-
@six.add_metaclass(abc.ABCMeta)
226-
class NetworkAndComputeLister(NetDetectionMixin, command.Lister):
223+
class NetworkAndComputeLister(NetDetectionMixin, command.Lister,
224+
metaclass=abc.ABCMeta):
227225
"""Network and Compute Lister
228226
229227
Lister class for commands that support implementation via
@@ -234,8 +232,8 @@ class NetworkAndComputeLister(NetDetectionMixin, command.Lister):
234232
pass
235233

236234

237-
@six.add_metaclass(abc.ABCMeta)
238-
class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne):
235+
class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne,
236+
metaclass=abc.ABCMeta):
239237
"""Network and Compute ShowOne
240238
241239
ShowOne class for commands that support implementation via
@@ -255,5 +253,5 @@ def take_action(self, parsed_args):
255253
except openstack.exceptions.HttpException as exc:
256254
msg = _("Error while executing command: %s") % exc.message
257255
if exc.details:
258-
msg += ", " + six.text_type(exc.details)
256+
msg += ", " + str(exc.details)
259257
raise exceptions.CommandError(msg)

openstackclient/shell.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
"""Command-line interface to the OpenStack APIs"""
1818

19-
import locale
2019
import sys
2120

2221
from osc_lib.api import auth
2322
from osc_lib.command import commandmanager
2423
from osc_lib import shell
25-
import six
2624

2725
import openstackclient
2826
from openstackclient.common import clientmanager
@@ -143,12 +141,6 @@ def initialize_app(self, argv):
143141
def main(argv=None):
144142
if argv is None:
145143
argv = sys.argv[1:]
146-
if six.PY2:
147-
# Emulate Py3, decode argv into Unicode based on locale so that
148-
# commands always see arguments as text instead of binary data
149-
encoding = locale.getpreferredencoding()
150-
if encoding:
151-
argv = map(lambda arg: arg.decode(encoding), argv)
152144

153145
return OpenStackShell().run(argv)
154146

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from osc_lib import exceptions
2525
from osc_lib import utils as common_utils
2626
from oslo_utils import timeutils
27-
import six
2827

2928
from openstackclient.compute.v2 import server
3029
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -1907,7 +1906,7 @@ def test_server_create_volume_boot_from_volume_conflict(self):
19071906
self.cmd.take_action, parsed_args)
19081907
# Assert it is the error we expect.
19091908
self.assertIn('--volume is not allowed with --boot-from-volume',
1910-
six.text_type(ex))
1909+
str(ex))
19111910

19121911
def test_server_create_image_property(self):
19131912
arglist = [
@@ -3288,7 +3287,7 @@ def test_server_migrate_with_host_pre_2_56(self):
32883287
# Make sure it's the error we expect.
32893288
self.assertIn('--os-compute-api-version 2.56 or greater is required '
32903289
'to use --host without --live-migration.',
3291-
six.text_type(ex))
3290+
str(ex))
32923291

32933292
self.servers_mock.get.assert_called_with(self.server.id)
32943293
self.assertNotCalled(self.servers_mock.live_migrate)
@@ -3323,7 +3322,7 @@ def test_server_live_migrate(self):
33233322
# A warning should have been logged for using --live.
33243323
mock_warning.assert_called_once()
33253324
self.assertIn('The --live option has been deprecated.',
3326-
six.text_type(mock_warning.call_args[0][0]))
3325+
str(mock_warning.call_args[0][0]))
33273326

33283327
def test_server_live_migrate_host_pre_2_30(self):
33293328
# Tests that the --host option is not supported for --live-migration
@@ -3346,7 +3345,7 @@ def test_server_live_migrate_host_pre_2_30(self):
33463345

33473346
# Make sure it's the error we expect.
33483347
self.assertIn('--os-compute-api-version 2.30 or greater is required '
3349-
'when using --host', six.text_type(ex))
3348+
'when using --host', str(ex))
33503349

33513350
self.servers_mock.get.assert_called_with(self.server.id)
33523351
self.assertNotCalled(self.servers_mock.live_migrate)
@@ -3436,7 +3435,7 @@ def test_server_live_migrate_without_host_override_live(self):
34363435
# A warning should have been logged for using --live.
34373436
mock_warning.assert_called_once()
34383437
self.assertIn('The --live option has been deprecated.',
3439-
six.text_type(mock_warning.call_args[0][0]))
3438+
str(mock_warning.call_args[0][0]))
34403439

34413440
def test_server_live_migrate_live_and_host_mutex(self):
34423441
# Tests specifying both the --live and --host options which are in a
@@ -4352,7 +4351,7 @@ def test_server_resize_confirm(self):
43524351
# A warning should have been logged for using --confirm.
43534352
mock_warning.assert_called_once()
43544353
self.assertIn('The --confirm option has been deprecated.',
4355-
six.text_type(mock_warning.call_args[0][0]))
4354+
str(mock_warning.call_args[0][0]))
43564355

43574356
def test_server_resize_revert(self):
43584357
arglist = [
@@ -4377,7 +4376,7 @@ def test_server_resize_revert(self):
43774376
# A warning should have been logged for using --revert.
43784377
mock_warning.assert_called_once()
43794378
self.assertIn('The --revert option has been deprecated.',
4380-
six.text_type(mock_warning.call_args[0][0]))
4379+
str(mock_warning.call_args[0][0]))
43814380

43824381
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
43834382
def test_server_resize_with_wait_ok(self, mock_wait_for_status):

openstackclient/tests/unit/compute/v2/test_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from novaclient import api_versions
2020
from osc_lib import exceptions
21-
import six
2221

2322
from openstackclient.compute.v2 import service
2423
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -502,7 +501,7 @@ def test_service_set_find_service_by_host_and_binary_no_results(self):
502501
self.cmd._find_service_by_host_and_binary,
503502
self.service_mock, 'fake-host', 'nova-compute')
504503
self.assertIn('Compute service for host "fake-host" and binary '
505-
'"nova-compute" not found.', six.text_type(ex))
504+
'"nova-compute" not found.', str(ex))
506505

507506
def test_service_set_find_service_by_host_and_binary_many_results(self):
508507
# Tests that more than one compute service is found by host and binary.
@@ -512,4 +511,4 @@ def test_service_set_find_service_by_host_and_binary_many_results(self):
512511
self.service_mock, 'fake-host', 'nova-compute')
513512
self.assertIn('Multiple compute services found for host "fake-host" '
514513
'and binary "nova-compute". Unable to proceed.',
515-
six.text_type(ex))
514+
str(ex))

0 commit comments

Comments
 (0)