Replace six.iteritems(iter) with iter.items()

As mentioned in [1], we should avoid using six.iteritems(iter) to
achieve iterators. We can use iter.items() instead, as it will
return iterators in PY3 as well.

[1] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: Ic41abf2ca6ec3ecb651b980091b52d0a185c9089
This commit is contained in:
xianming mao
2016-12-01 20:18:26 +08:00
parent b8ed0c2d27
commit 8a4f61a93d
5 changed files with 6 additions and 12 deletions

View File

@@ -293,7 +293,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:
@@ -489,7 +489,7 @@ class Resource(RequestIdMixin):
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:
try: try:
setattr(self, k, v) setattr(self, k, v)

View File

@@ -23,8 +23,6 @@ Exception definitions.
import inspect import inspect
import sys import sys
import six
class ClientException(Exception): class ClientException(Exception):
"""The base exception class for all exceptions this library raises. """The base exception class for all exceptions this library raises.
@@ -396,7 +394,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)
) )

View File

@@ -17,8 +17,6 @@
import logging import logging
import pkg_resources import pkg_resources
import six
from cinderclient import exceptions from cinderclient import exceptions
from cinderclient import utils from cinderclient import utils
@@ -51,7 +49,7 @@ def load_auth_system_opts(parser):
This function will try to populate the parser with options from the This function will try to populate the parser with options from the
available plugins. available plugins.
""" """
for name, auth_plugin in six.iteritems(_discovered_plugins): for name, auth_plugin in _discovered_plugins.items():
add_opts_fn = getattr(auth_plugin, "add_opts", None) add_opts_fn = getattr(auth_plugin, "add_opts", None)
if add_opts_fn: if add_opts_fn:
group = parser.add_argument_group("Auth-system '%s' options" % group = parser.add_argument_group("Auth-system '%s' options" %

View File

@@ -211,7 +211,7 @@ def print_dict(d, property="Property", formatters=None):
pt.align = 'l' pt.align = 'l'
formatters = formatters or {} formatters = formatters or {}
for r in six.iteritems(d): for r in d.items():
r = list(r) r = list(r)
if r[0] in formatters: if r[0] in formatters:

View File

@@ -15,8 +15,6 @@
"""Pools interface (v3 extension)""" """Pools interface (v3 extension)"""
import six
from cinderclient import base from cinderclient import base
@@ -45,7 +43,7 @@ class PoolManager(base.Manager):
# be attributes of the pool itself. # be attributes of the pool itself.
for pool in pools: for pool in pools:
if hasattr(pool, 'capabilities'): if hasattr(pool, 'capabilities'):
for k, v in six.iteritems(pool.capabilities): for k, v in pool.capabilities.items():
setattr(pool, k, v) setattr(pool, k, v)
# Remove the capabilities dictionary since all of its # Remove the capabilities dictionary since all of its