Replace dict.iteritems() with dict.items() in keystone

1.As mentioned in [1], we should avoid using dict.iteritems
  to achieve iterators. We can use dict.items instead, as it
  will return iterators in PY3 as well. And dict.items will
  more readable.
2.In py2, the performance about list should be negligible,
  see the link [2].

[1] https://wiki.openstack.org/wiki/Python3#Common_patterns
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I7363b807f2f8ce7da09403985939583966e000de
This commit is contained in:
yanghuichan 2017-08-07 14:19:36 +08:00 committed by Colleen Murphy
parent 9cbd6bc0eb
commit c702aa361a

View File

@ -95,8 +95,8 @@ class SmarterEncoder(jsonutils.json.JSONEncoder):
"""Help for JSON encoding dict-like objects."""
def default(self, obj):
if not isinstance(obj, dict) and hasattr(obj, 'iteritems'):
return dict(obj.iteritems())
if not isinstance(obj, dict) and hasattr(obj, 'items'):
return dict(obj.items())
return super(SmarterEncoder, self).default(obj)