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: Ib3740617715c7097efeb5852338a669dc0bf8ff7
This commit is contained in:
parent
c1c64f8511
commit
3e70d5be31
|
@ -54,7 +54,7 @@ def load_auth_system_opts(parser):
|
|||
"""
|
||||
group = parser.add_argument_group("Common auth options")
|
||||
BaseAuthPlugin.add_common_opts(group)
|
||||
for name, auth_plugin in six.iteritems(_discovered_plugins):
|
||||
for name, auth_plugin in _discovered_plugins.items():
|
||||
group = parser.add_argument_group(
|
||||
"Auth-system '%s' options" % name,
|
||||
conflict_handler="resolve")
|
||||
|
|
|
@ -297,7 +297,7 @@ class CrudManager(BaseManager):
|
|||
|
||||
def _filter_kwargs(self, kwargs):
|
||||
"""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:
|
||||
kwargs.pop(key)
|
||||
else:
|
||||
|
@ -470,7 +470,7 @@ class Resource(object):
|
|||
return None
|
||||
|
||||
def _add_details(self, info):
|
||||
for (k, v) in six.iteritems(info):
|
||||
for (k, v) in info.items():
|
||||
try:
|
||||
setattr(self, k, v)
|
||||
self._info[k] = v
|
||||
|
|
|
@ -22,8 +22,6 @@ Exception definitions.
|
|||
import inspect
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from muranoclient.i18n import _
|
||||
|
||||
|
||||
|
@ -410,7 +408,7 @@ class HttpVersionNotSupported(HttpServerError):
|
|||
# _code_map contains all the classes that have http_status attribute.
|
||||
_code_map = dict(
|
||||
(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)
|
||||
)
|
||||
|
||||
|
|
|
@ -401,8 +401,8 @@ class Package(FileWrapperMixin):
|
|||
if not hasattr(self, '_classes'):
|
||||
self._classes = {}
|
||||
self._resolvers = {}
|
||||
for class_name, class_file in six.iteritems(
|
||||
self.manifest.get('Classes', {})):
|
||||
for class_name, class_file in (
|
||||
self.manifest.get('Classes', {}).items()):
|
||||
filename = "Classes/%s" % class_file
|
||||
if filename not in self.contents.namelist():
|
||||
continue
|
||||
|
@ -527,7 +527,7 @@ class Package(FileWrapperMixin):
|
|||
def _get_direct_deps(package, base_url, path):
|
||||
result = []
|
||||
if 'Require' in package.manifest:
|
||||
for dep_name, ver in six.iteritems(package.manifest['Require']):
|
||||
for dep_name, ver in package.manifest['Require'].items():
|
||||
try:
|
||||
req_file = Package.from_location(
|
||||
dep_name,
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
from glanceclient import exc
|
||||
import six
|
||||
|
||||
|
||||
class ArtifactType(object):
|
||||
|
@ -32,7 +31,7 @@ class ArtifactType(object):
|
|||
msg = "Invalid parameters were provided"
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
self.type_specific_properties = {}
|
||||
for key, value in six.iteritems(kwargs):
|
||||
for key, value in kwargs.items():
|
||||
try:
|
||||
if _is_dependency(value):
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ class Controller(object):
|
|||
filters['limit'] = page_size
|
||||
|
||||
url_params = []
|
||||
for param, items in six.iteritems(filters):
|
||||
for param, items in filters.items():
|
||||
values = [items] if not isinstance(items, list) else items
|
||||
for value in values:
|
||||
if isinstance(value, six.string_types):
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
import os
|
||||
|
||||
import fixtures
|
||||
import six
|
||||
import testtools
|
||||
|
||||
|
||||
|
@ -42,4 +41,4 @@ class TestAdditionalAsserts(testtools.TestCase):
|
|||
def check_dict_is_subset(self, dict1, dict2):
|
||||
# There is an assert for this in Python 2.7 but not 2.6
|
||||
self.assertTrue(all(k in dict2 and dict2[k] == v for k, v
|
||||
in six.iteritems(dict1)))
|
||||
in dict1.items()))
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import collections
|
||||
|
||||
from glanceclient import exc as glance_exc
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from muranoclient.common import exceptions as exc
|
||||
|
@ -51,7 +50,7 @@ class ArtifactRepo(object):
|
|||
'tags': manifest.get('Tags', []),
|
||||
'class_definitions': package.classes.keys()
|
||||
}
|
||||
for k, v in six.iteritems(kwargs):
|
||||
for k, v in kwargs.items():
|
||||
package_draft[k] = v
|
||||
|
||||
inherits = self._get_local_inheritance(package.classes,
|
||||
|
@ -112,7 +111,7 @@ class ArtifactRepo(object):
|
|||
@staticmethod
|
||||
def _get_local_inheritance(classes, resolvers):
|
||||
result = {}
|
||||
for class_name, klass in six.iteritems(classes):
|
||||
for class_name, klass in classes.items():
|
||||
if 'Extends' not in klass:
|
||||
continue
|
||||
ns = klass.get('Namespaces')
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
from six.moves import urllib
|
||||
|
||||
from muranoclient.common import base
|
||||
|
@ -40,7 +39,7 @@ class CategoryManager(base.Manager):
|
|||
"""
|
||||
|
||||
params = {}
|
||||
for key, value in six.iteritems(kwargs):
|
||||
for key, value in kwargs.items():
|
||||
if value:
|
||||
params[key] = value
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import six
|
||||
from six.moves import urllib
|
||||
|
||||
from muranoclient.common import base
|
||||
|
@ -73,7 +72,7 @@ class EnvironmentManager(base.ManagerWithFind):
|
|||
response_key='lastStatuses',
|
||||
headers=headers)
|
||||
result = {}
|
||||
for k, v in six.iteritems(status_dict):
|
||||
for k, v in status_dict.items():
|
||||
if v:
|
||||
result[k] = Status(self, v, loaded=True)
|
||||
return result
|
||||
|
|
|
@ -125,7 +125,7 @@ class PackageManager(base.Manager):
|
|||
"""
|
||||
url = '/v1/catalog/packages/{0}'.format(app_id)
|
||||
data = []
|
||||
for key, value in six.iteritems(body):
|
||||
for key, value in body.items():
|
||||
data.append({'op': operation, 'path': '/' + key, 'value': value})
|
||||
return self.api.json_patch_request(url, data=data)
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import zipfile
|
|||
import jsonpatch
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import six.moves
|
||||
|
||||
from muranoclient.apiclient import exceptions
|
||||
|
@ -820,7 +819,7 @@ def do_package_import(mc, args):
|
|||
if dep_exists_action == '':
|
||||
dep_exists_action = args.exists_action
|
||||
|
||||
for name, package in six.iteritems(total_reqs):
|
||||
for name, package in total_reqs.items():
|
||||
image_specs = package.images()
|
||||
if image_specs:
|
||||
print("Inspecting required images")
|
||||
|
@ -939,7 +938,7 @@ def do_bundle_import(mc, args):
|
|||
|
||||
imported_list = []
|
||||
|
||||
for name, dep_package in six.iteritems(total_reqs):
|
||||
for name, dep_package in total_reqs.items():
|
||||
image_specs = dep_package.images()
|
||||
if image_specs:
|
||||
print("Inspecting required images")
|
||||
|
@ -973,7 +972,7 @@ def do_bundle_import(mc, args):
|
|||
def _handle_save_packages(packages, dst, base_url, no_images):
|
||||
downloaded_images = []
|
||||
|
||||
for name, pkg in six.iteritems(packages):
|
||||
for name, pkg in packages.items():
|
||||
if not no_images:
|
||||
image_specs = pkg.images()
|
||||
for image_spec in image_specs:
|
||||
|
|
Loading…
Reference in New Issue