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: Idb02425dbefb6ea9038b625d6286e377988b2c03
This commit is contained in:
parent
5e94996791
commit
fb3e26044d
|
@ -317,7 +317,7 @@ class CrudManager(BaseManager):
|
||||||
|
|
||||||
def _filter_kwargs(self, kwargs):
|
def _filter_kwargs(self, kwargs):
|
||||||
"""Drop null values and handle ids."""
|
"""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:
|
if ref is None:
|
||||||
kwargs.pop(key)
|
kwargs.pop(key)
|
||||||
else:
|
else:
|
||||||
|
@ -476,7 +476,7 @@ class Resource(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _add_details(self, info):
|
def _add_details(self, info):
|
||||||
for (k, v) in six.iteritems(info):
|
for (k, v) in info.items():
|
||||||
try:
|
try:
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
self._info[k] = v
|
self._info[k] = v
|
||||||
|
|
|
@ -423,7 +423,7 @@ class HttpVersionNotSupported(HttpServerError):
|
||||||
# _code_map contains all the classes that have http_status attribute.
|
# _code_map contains all the classes that have http_status attribute.
|
||||||
_code_map = dict(
|
_code_map = dict(
|
||||||
(getattr(obj, 'http_status', None), obj)
|
(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)
|
if inspect.isclass(obj) and getattr(obj, 'http_status', False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
"""Searchlight v1 Facet action implementations"""
|
"""Searchlight v1 Facet action implementations"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import six
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
@ -63,7 +62,7 @@ class ListFacet(command.Lister):
|
||||||
}
|
}
|
||||||
data = search_client.facets.list(**params)
|
data = search_client.facets.list(**params)
|
||||||
result = []
|
result = []
|
||||||
for resource_type, values in six.iteritems(data):
|
for resource_type, values in data.items():
|
||||||
if isinstance(values, list):
|
if isinstance(values, list):
|
||||||
# Cope with pre-1.0 service APIs
|
# Cope with pre-1.0 service APIs
|
||||||
facets = values
|
facets = values
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import six
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
@ -118,7 +117,7 @@ class SearchResource(command.Lister):
|
||||||
# hit._id may include extra information appended after _,
|
# hit._id may include extra information appended after _,
|
||||||
# so use r['_source']['id'] for safe.
|
# so use r['_source']['id'] for safe.
|
||||||
r['_id'] = r.get('_source', {}).get('id')
|
r['_id'] = r.get('_source', {}).get('id')
|
||||||
for k, v in six.iteritems(r):
|
for k, v in r.items():
|
||||||
map_key = mapping.get(k)
|
map_key = mapping.get(k)
|
||||||
if map_key is not None:
|
if map_key is not None:
|
||||||
converted[map_key] = v
|
converted[map_key] = v
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import six
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ class FakeResource(object):
|
||||||
self._loaded = loaded
|
self._loaded = loaded
|
||||||
|
|
||||||
def _add_details(self, info):
|
def _add_details(self, info):
|
||||||
for (k, v) in six.iteritems(info):
|
for (k, v) in info.items():
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from searchlightclient.common import base
|
from searchlightclient.common import base
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +41,7 @@ class SearchManager(base.BaseManager):
|
||||||
current project unless all_projects is set
|
current project unless all_projects is set
|
||||||
"""
|
"""
|
||||||
search_params = {}
|
search_params = {}
|
||||||
for k, v in six.iteritems(kwargs):
|
for k, v in kwargs.items():
|
||||||
if k in ('query', 'type', 'offset',
|
if k in ('query', 'type', 'offset',
|
||||||
'limit', 'sort', '_source', 'highlight', 'all_projects'):
|
'limit', 'sort', '_source', 'highlight', 'all_projects'):
|
||||||
search_params[k] = v
|
search_params[k] = v
|
||||||
|
|
Loading…
Reference in New Issue