Replace six.iteritems() with .items()
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 Python 3 as well, and it is more readable. In Python 2, the overhead of dict.items() creating a new list should be negligible for most use cases in OpenStack [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: I620c9cc201c62f033a5467aa52625b56e19933cb
This commit is contained in:
@@ -84,7 +84,7 @@ class BlazarCommand(OpenStackCommand):
|
||||
return parser
|
||||
|
||||
def format_output_data(self, data):
|
||||
for k, v in six.iteritems(data):
|
||||
for k, v in data.items():
|
||||
if isinstance(v, six.text_type):
|
||||
try:
|
||||
# Deserialize if possible into dict, lists, tuples...
|
||||
@@ -134,7 +134,7 @@ class CreateCommand(BlazarCommand, show.ShowOne):
|
||||
print(self.app.stdout, 'Created a new %s:' % self.resource)
|
||||
else:
|
||||
data = {'': ''}
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
|
||||
class UpdateCommand(BlazarCommand):
|
||||
@@ -291,4 +291,4 @@ class ShowCommand(BlazarCommand, show.ShowOne):
|
||||
resource_manager = getattr(blazar_client, self.resource)
|
||||
data = resource_manager.get(res_id)
|
||||
self.format_output_data(data)
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
@@ -17,7 +17,6 @@ import datetime
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
|
||||
from blazarclient import exception
|
||||
from blazarclient.i18n import _
|
||||
@@ -52,13 +51,13 @@ def to_primitive(value):
|
||||
return o
|
||||
elif isinstance(value, dict):
|
||||
o = {}
|
||||
for k, v in six.iteritems(value):
|
||||
for k, v in value.items():
|
||||
o[k] = to_primitive(v)
|
||||
return o
|
||||
elif isinstance(value, datetime.datetime):
|
||||
return str(value)
|
||||
elif hasattr(value, 'iteritems'):
|
||||
return to_primitive(dict(six.iteritems(value)))
|
||||
return to_primitive(dict(value.items()))
|
||||
elif hasattr(value, '__iter__'):
|
||||
return to_primitive(list(value))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user