[2/3]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

The patch list:
    1. cells.
    2. compute api.
    3. image.
    4. network.
    5. objects.
    6. scheduler.
    7. virt.
    8. other resources.

Partial-Implements: blueprint replace-iteritems-with-items

Change-Id: Ic6e469eb80ee1774de1374bb36f38b5134b6b311
This commit is contained in:
Spencer Yu
2016-12-20 23:43:53 -08:00
parent f55815b2f9
commit 70730c09ab
45 changed files with 91 additions and 93 deletions

View File

@@ -928,7 +928,7 @@ def metadata_to_dict(metadata, include_deleted=False):
def dict_to_metadata(metadata):
result = []
for key, value in six.iteritems(metadata):
for key, value in metadata.items():
result.append(dict(key=key, value=value))
return result
@@ -1133,7 +1133,7 @@ def get_system_metadata_from_image(image_meta, flavor=None):
system_meta = {}
prefix_format = SM_IMAGE_PROP_PREFIX + '%s'
for key, value in six.iteritems(image_meta.get('properties', {})):
for key, value in image_meta.get('properties', {}).items():
if key in SM_SKIP_KEYS:
continue
@@ -1164,7 +1164,7 @@ def get_image_from_system_metadata(system_meta):
if not isinstance(system_meta, dict):
system_meta = metadata_to_dict(system_meta, include_deleted=True)
for key, value in six.iteritems(system_meta):
for key, value in system_meta.items():
if value is None:
continue
@@ -1295,7 +1295,7 @@ def filter_and_format_resource_metadata(resource_type, resource_list,
if ids and _get_id(resource) not in ids:
return {}
for k, v in six.iteritems(input_metadata):
for k, v in input_metadata.items():
# Both keys and value defined -- AND
if (keys_filter and values_filter and
not _match_any(keys_filter, k) and