Replace six.iteritems() with .items()

1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can
use dict.items instead, as it will return
iterators in PY3 as well. And dict.items/keys
will more readable. 2.In py2, the performance
about list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I159cf82541e43468b106e8e22373a0a24a4f6a53
This commit is contained in:
ji-xuepeng 2017-02-07 22:32:49 +08:00
parent 56776ce009
commit e627decb4d
12 changed files with 16 additions and 25 deletions

View File

@ -54,7 +54,7 @@ def load_auth_system_opts(parser):
"""
group = parser.add_argument_group("Common auth options")
BaseAuthPlugin.add_common_opts(group)
for name, auth_plugin in six.iteritems(_discovered_plugins):
for name, auth_plugin in _discovered_plugins.items():
group = parser.add_argument_group(
"Auth-system '%s' options" % name,
conflict_handler="resolve")

View File

@ -303,7 +303,7 @@ class CrudManager(BaseManager):
def _filter_kwargs(self, kwargs):
"""Drop null values and handle ids."""
for key, ref in six.iteritems(kwargs.copy()):
for key, ref in kwargs.copy().items():
if ref is None:
kwargs.pop(key)
else:
@ -461,7 +461,7 @@ class Resource(object):
return None
def _add_details(self, info):
for (k, v) in six.iteritems(info):
for (k, v) in info.items():
try:
setattr(self, k, v)
self._info[k] = v

View File

@ -421,7 +421,7 @@ class HttpVersionNotSupported(HttpServerError):
# _code_map contains all the classes that have http_status attribute.
_code_map = dict(
(getattr(obj, 'http_status', None), obj)
for name, obj in six.iteritems(vars(sys.modules[__name__]))
for name, obj in vars(sys.modules[__name__]).items()
if inspect.isclass(obj) and getattr(obj, 'http_status', False)
)

View File

@ -195,7 +195,7 @@ def print_dict(dct, dict_property="Property", wrap=0):
"""
pt = prettytable.PrettyTable([dict_property, 'Value'])
pt.align = 'l'
for k, v in six.iteritems(dct):
for k, v in dct.items():
# convert dict to str to check length
if isinstance(v, dict):
v = six.text_type(v)

View File

@ -14,7 +14,6 @@
# under the License.
import ddt
import six
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions as tempest_lib_exc
@ -91,7 +90,7 @@ class ShareNetworksReadWriteTest(base.BaseTestCase):
'neutron_net_id': 'None',
'neutron_subnet_id': 'None',
}
update_values = dict([(k, v) for k, v in six.iteritems(net_data)
update_values = dict([(k, v) for k, v in net_data.items()
if v != '""'])
expected_data.update(update_values)

View File

@ -1363,7 +1363,7 @@ class ShellTest(test_utils.TestCase):
'limit': 20,
}
command_str = 'share-network-list'
for key, value in six.iteritems(filters):
for key, value in filters.items():
command_str += ' --%(key)s=%(value)s' % {'key': key,
'value': value}
self.run_command(command_str)
@ -1687,7 +1687,7 @@ class ShellTest(test_utils.TestCase):
'limit': 20,
}
command_str = 'security-service-list'
for key, value in six.iteritems(filters):
for key, value in filters.items():
command_str += ' --%(key)s=%(value)s' % {'key': key,
'value': value}
self.run_command(command_str)

View File

@ -16,7 +16,6 @@ from keystoneclient import adapter
from keystoneclient import client as ks_client
from keystoneclient import discover
from keystoneclient import session
import six
import manilaclient
from manilaclient.common import constants
@ -117,7 +116,7 @@ class Client(object):
'api_key': 'password',
}
for arg, replacement in six.iteritems(deprecated):
for arg, replacement in deprecated.items():
if kwargs.get(arg, None) is None:
continue

View File

@ -16,7 +16,6 @@ from keystoneclient import adapter
from keystoneclient import client as ks_client
from keystoneclient import discover
from keystoneclient import session
import six
import manilaclient
from manilaclient.common import constants
@ -129,7 +128,7 @@ class Client(object):
'api_key': 'password',
}
for arg, replacement in six.iteritems(deprecated):
for arg, replacement in deprecated.items():
if kwargs.get(arg, None) is None:
continue

View File

@ -18,8 +18,6 @@ try:
except ImportError:
from urllib.parse import urlencode # noqa
import six
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient import exceptions
@ -126,7 +124,7 @@ class SecurityServiceManager(base.ManagerWithFind):
if description is not None:
values['description'] = description
for k, v in six.iteritems(values):
for k, v in values.items():
if v == '':
values[k] = None

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
try:
from urllib import urlencode # noqa
except ImportError:
@ -50,7 +49,7 @@ class ServiceManager(base.Manager):
query_string = ''
if search_opts:
query_string = urlencode(
sorted([(k, v) for (k, v) in six.iteritems(search_opts) if v]))
sorted([(k, v) for (k, v) in search_opts.items() if v]))
if query_string:
query_string = "?%s" % query_string
return self._list(resource_path + query_string, RESOURCE_NAME)

View File

@ -18,8 +18,6 @@ try:
except ImportError:
from urllib.parse import urlencode # noqa
import six
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
@ -169,7 +167,7 @@ class ShareNetworkManager(base.ManagerWithFind):
if description is not None:
values['description'] = description
for k, v in six.iteritems(values):
for k, v in values.items():
if v == '':
values[k] = None
@ -201,7 +199,7 @@ class ShareNetworkManager(base.ManagerWithFind):
if description is not None:
values['description'] = description
for k, v in six.iteritems(values):
for k, v in values.items():
if v == '':
values[k] = None

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
try:
from urllib import urlencode # noqa
except ImportError:
@ -63,7 +62,7 @@ class ShareServerManager(base.ManagerWithFind):
# +---------------------+------------------------------------+
# | details:instance_id |35203a78-c733-4b1f-b82c-faded312e537|
# +---------------------+------------------------------------+
for k, v in six.iteritems(server._info["backend_details"]):
for k, v in server._info["backend_details"].items():
server._info["details:%s" % k] = v
return server
@ -93,7 +92,7 @@ class ShareServerManager(base.ManagerWithFind):
query_string = ''
if search_opts:
opts = sorted(
[(k, v) for (k, v) in six.iteritems(search_opts) if v])
[(k, v) for (k, v) in search_opts.items() if v])
query_string = urlencode(opts)
query_string = '?' + query_string if query_string else ''
return self._list(RESOURCES_PATH + query_string, RESOURCES_NAME)