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: I6289f46344876d19d9a6793875f896cedc85a01c
This commit is contained in:
parent
e490688b11
commit
56bb3dae5f
@ -162,7 +162,7 @@ class Resource(RequestIdMixin):
|
||||
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
|
||||
@ -488,7 +488,7 @@ class BootingManagerWithFind(ManagerWithFind):
|
||||
|
||||
bdm = []
|
||||
|
||||
for device_name, mapping in six.iteritems(block_device_mapping):
|
||||
for device_name, mapping in block_device_mapping.items():
|
||||
#
|
||||
# The mapping is in the format:
|
||||
# <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
|
||||
|
@ -207,7 +207,7 @@ def _flatten(data, prefix=None):
|
||||
|
||||
"""
|
||||
if isinstance(data, dict):
|
||||
for key, value in six.iteritems(data):
|
||||
for key, value in data.items():
|
||||
new_key = '%s_%s' % (prefix, key) if prefix else key
|
||||
if isinstance(value, (dict, list)) and value:
|
||||
for item in _flatten(value, new_key):
|
||||
@ -230,7 +230,7 @@ def flatten_dict(data):
|
||||
"""
|
||||
data = data.copy()
|
||||
# Try and decode any nested JSON structures.
|
||||
for key, value in six.iteritems(data):
|
||||
for key, value in data.items():
|
||||
if isinstance(value, six.string_types):
|
||||
try:
|
||||
data[key] = json.loads(value)
|
||||
|
@ -17,7 +17,6 @@
|
||||
Security group interface (1.1 extension).
|
||||
"""
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient import api_versions
|
||||
@ -108,7 +107,7 @@ class SecurityGroupManager(base.ManagerWithFind):
|
||||
"""
|
||||
search_opts = search_opts or {}
|
||||
|
||||
qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
|
||||
qparams = dict((k, v) for (k, v) in search_opts.items() if v)
|
||||
|
||||
query_string = '?%s' % parse.urlencode(qparams) if qparams else ''
|
||||
|
||||
|
@ -795,7 +795,7 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
|
||||
qparams = {}
|
||||
|
||||
for opt, val in six.iteritems(search_opts):
|
||||
for opt, val in search_opts.items():
|
||||
if val:
|
||||
if isinstance(val, six.text_type):
|
||||
val = val.encode('utf-8')
|
||||
|
@ -155,7 +155,7 @@ def _parse_block_device_mapping_v2(args, image):
|
||||
spec_dict = dict(v.split('=') for v in device_spec.split(','))
|
||||
bdm_dict = {}
|
||||
|
||||
for key, value in six.iteritems(spec_dict):
|
||||
for key, value in spec_dict.items():
|
||||
bdm_dict[CLIENT_BDM2_KEYS[key]] = value
|
||||
|
||||
# Convert the delete_on_termination to a boolean or set it to true by
|
||||
|
Loading…
x
Reference in New Issue
Block a user