py3.x: Use six.iteritems for Iterable dict items.
py3.x: Use six.iteritems for Iterable dict items instead of dict.iteritems. Related-Bug: #1547712 Change-Id: I1e66c1e2a3f0235029795e48e8779229420d4821
This commit is contained in:
parent
eb7353fe34
commit
643e73095a
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from six import iteritems
|
||||
from six.moves.urllib import parse as urllib_parse
|
||||
from webob import exc
|
||||
|
||||
|
@ -36,7 +37,7 @@ def get_filters(request, attr_info, skips=None):
|
|||
res = {}
|
||||
if skips is None:
|
||||
skips = []
|
||||
for key, values in request.GET.dict_of_lists().iteritems():
|
||||
for key, values in iteritems(request.GET.dict_of_lists()):
|
||||
if key in skips:
|
||||
continue
|
||||
values = [v for v in values if v]
|
||||
|
|
|
@ -167,7 +167,7 @@ class ExtensionDescriptor(object):
|
|||
if not extension_attrs_map:
|
||||
return
|
||||
|
||||
for resource, attrs in extension_attrs_map.iteritems():
|
||||
for resource, attrs in six.iteritems(extension_attrs_map):
|
||||
extended_attrs = extended_attributes.get(resource)
|
||||
if extended_attrs:
|
||||
attrs.update(extended_attrs)
|
||||
|
@ -197,7 +197,7 @@ class ActionExtensionController(wsgi.Controller):
|
|||
def action(self, request, id):
|
||||
input_dict = self._deserialize(request.body,
|
||||
request.get_content_type())
|
||||
for action_name, handler in self.action_handlers.iteritems():
|
||||
for action_name, handler in six.iteritems(self.action_handlers):
|
||||
if action_name in input_dict:
|
||||
return handler(input_dict, request, id)
|
||||
# no action handler found (bump to downstream application)
|
||||
|
@ -239,7 +239,7 @@ class ExtensionController(wsgi.Controller):
|
|||
|
||||
def index(self, request):
|
||||
extensions = []
|
||||
for _alias, ext in self.extension_manager.extensions.iteritems():
|
||||
for _alias, ext in six.iteritems(self.extension_manager.extensions):
|
||||
extensions.append(self._translate(ext))
|
||||
return dict(extensions=extensions)
|
||||
|
||||
|
@ -280,7 +280,7 @@ class ExtensionMiddleware(wsgi.Middleware):
|
|||
|
||||
LOG.debug(_('Extended resource: %s'),
|
||||
resource.collection)
|
||||
for action, method in resource.collection_actions.iteritems():
|
||||
for action, method in six.iteritems(resource.collection_actions):
|
||||
conditions = dict(method=[method])
|
||||
path = "/%s/%s" % (resource.collection, action)
|
||||
with mapper.submapper(controller=resource.controller,
|
||||
|
@ -480,7 +480,8 @@ class ExtensionManager(object):
|
|||
continue
|
||||
try:
|
||||
extended_attrs = ext.get_extended_resources(version)
|
||||
for resource, resource_attrs in extended_attrs.iteritems():
|
||||
for resource, resource_attrs in six.iteritems(
|
||||
extended_attrs):
|
||||
if attr_map.get(resource, None):
|
||||
attr_map[resource].update(resource_attrs)
|
||||
else:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import re
|
||||
|
||||
import netaddr
|
||||
from six import iteritems
|
||||
|
||||
from tacker.common import constants
|
||||
from tacker.common import exceptions as n_exc
|
||||
|
@ -390,7 +391,7 @@ def _validate_dict_item(key, key_validator, data):
|
|||
# TODO(salv-orlando): Structure of dict attributes should be improved
|
||||
# to avoid iterating over items
|
||||
val_func = val_params = None
|
||||
for (k, v) in key_validator.iteritems():
|
||||
for (k, v) in iteritems(key_validator):
|
||||
if k.startswith('type:'):
|
||||
# ask forgiveness, not permission
|
||||
try:
|
||||
|
@ -414,7 +415,7 @@ def _validate_dict(data, key_specs=None):
|
|||
return
|
||||
|
||||
# Check whether all required keys are present
|
||||
required_keys = [key for key, spec in key_specs.iteritems()
|
||||
required_keys = [key for key, spec in iteritems(key_specs)
|
||||
if spec.get('required')]
|
||||
|
||||
if required_keys:
|
||||
|
@ -425,7 +426,7 @@ def _validate_dict(data, key_specs=None):
|
|||
|
||||
# Perform validation and conversion of all values
|
||||
# according to the specifications.
|
||||
for key, key_validator in [(k, v) for k, v in key_specs.iteritems()
|
||||
for key, key_validator in [(k, v) for k, v in iteritems(key_specs)
|
||||
if k in data]:
|
||||
msg = _validate_dict_item(key, key_validator, data)
|
||||
if msg:
|
||||
|
@ -516,7 +517,7 @@ def convert_kvp_list_to_dict(kvp_list):
|
|||
key, value = convert_kvp_str_to_list(kvp_str)
|
||||
kvp_map.setdefault(key, set())
|
||||
kvp_map[key].add(value)
|
||||
return dict((x, list(y)) for x, y in kvp_map.iteritems())
|
||||
return dict((x, list(y)) for x, y in iteritems(kvp_map))
|
||||
|
||||
|
||||
def convert_none_to_empty_list(value):
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import netaddr
|
||||
from six import iteritems
|
||||
import webob.exc
|
||||
|
||||
from tacker.api import api_common
|
||||
|
@ -90,7 +91,7 @@ class Controller(object):
|
|||
self._resource)
|
||||
|
||||
def _get_primary_key(self, default_primary_key='id'):
|
||||
for key, value in self._attr_info.iteritems():
|
||||
for key, value in iteritems(self._attr_info):
|
||||
if value.get('primary_key', False):
|
||||
return key
|
||||
return default_primary_key
|
||||
|
@ -150,7 +151,7 @@ class Controller(object):
|
|||
def _filter_attributes(self, context, data, fields_to_strip=None):
|
||||
if not fields_to_strip:
|
||||
return data
|
||||
return dict(item for item in data.iteritems()
|
||||
return dict(item for item in iteritems(data)
|
||||
if (item[0] not in fields_to_strip))
|
||||
|
||||
def _do_field_list(self, original_fields):
|
||||
|
@ -441,7 +442,7 @@ class Controller(object):
|
|||
# Load object to check authz
|
||||
# but pass only attributes in the original body and required
|
||||
# by the policy engine to the policy 'brain'
|
||||
field_list = [name for (name, value) in self._attr_info.iteritems()
|
||||
field_list = [name for (name, value) in iteritems(self._attr_info)
|
||||
if (value.get('required_by_policy') or
|
||||
value.get('primary_key') or
|
||||
'default' not in value)]
|
||||
|
@ -530,7 +531,7 @@ class Controller(object):
|
|||
Controller._verify_attributes(res_dict, attr_info)
|
||||
|
||||
if is_create: # POST
|
||||
for attr, attr_vals in attr_info.iteritems():
|
||||
for attr, attr_vals in iteritems(attr_info):
|
||||
if attr_vals['allow_post']:
|
||||
if ('default' not in attr_vals and
|
||||
attr not in res_dict):
|
||||
|
@ -544,12 +545,12 @@ class Controller(object):
|
|||
msg = _("Attribute '%s' not allowed in POST") % attr
|
||||
raise webob.exc.HTTPBadRequest(msg)
|
||||
else: # PUT
|
||||
for attr, attr_vals in attr_info.iteritems():
|
||||
for attr, attr_vals in iteritems(attr_info):
|
||||
if attr in res_dict and not attr_vals['allow_put']:
|
||||
msg = _("Cannot update read-only attribute %s") % attr
|
||||
raise webob.exc.HTTPBadRequest(msg)
|
||||
|
||||
for attr, attr_vals in attr_info.iteritems():
|
||||
for attr, attr_vals in iteritems(attr_info):
|
||||
if (attr not in res_dict or
|
||||
res_dict[attr] is attributes.ATTR_NOT_SPECIFIED):
|
||||
continue
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import routes as routes_mapper
|
||||
from six import iteritems
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import webob
|
||||
import webob.dec
|
||||
|
@ -38,7 +39,7 @@ class Index(wsgi.Application):
|
|||
'link': ['href', 'rel']}}}
|
||||
|
||||
layout = []
|
||||
for name, collection in self.resources.iteritems():
|
||||
for name, collection in iteritems(self.resources):
|
||||
href = urlparse.urljoin(req.path_url, collection)
|
||||
resource = {'name': name,
|
||||
'collection': collection,
|
||||
|
|
|
@ -34,6 +34,7 @@ from eventlet.green import subprocess
|
|||
import netaddr
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import importutils
|
||||
from six import iteritems
|
||||
from stevedore import driver
|
||||
|
||||
from tacker.common import constants as q_const
|
||||
|
@ -260,7 +261,7 @@ def compare_elements(a, b):
|
|||
|
||||
def dict2str(dic):
|
||||
return ','.join("%s=%s" % (key, val)
|
||||
for key, val in sorted(dic.iteritems()))
|
||||
for key, val in sorted(iteritems(dic)))
|
||||
|
||||
|
||||
def str2dict(string):
|
||||
|
@ -344,7 +345,7 @@ def change_memory_unit(mem, to):
|
|||
"""
|
||||
|
||||
mem = str(mem) + " MB" if str(mem).isdigit() else mem.upper()
|
||||
for unit, value in MEM_UNITS.iteritems():
|
||||
for unit, value in iteritems(MEM_UNITS):
|
||||
mem_arr = mem.split(unit)
|
||||
if len(mem_arr) < 2:
|
||||
continue
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
|
||||
import weakref
|
||||
|
||||
from six import iteritems
|
||||
from sqlalchemy import sql
|
||||
|
||||
from tacker.common import exceptions as n_exc
|
||||
from tacker.db import sqlalchemyutils
|
||||
from tacker.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -87,8 +87,7 @@ class CommonDbMixin(object):
|
|||
else:
|
||||
query_filter = (model.tenant_id == context.tenant_id)
|
||||
# Execute query hooks registered from mixins and plugins
|
||||
for _name, hooks in self._model_query_hooks.get(model,
|
||||
{}).iteritems():
|
||||
for _name, hooks in iteritems(self._model_query_hooks.get(model, {})):
|
||||
query_hook = hooks.get('query')
|
||||
if isinstance(query_hook, basestring):
|
||||
query_hook = getattr(self, query_hook, None)
|
||||
|
@ -130,12 +129,12 @@ class CommonDbMixin(object):
|
|||
|
||||
def _apply_filters_to_query(self, query, model, filters):
|
||||
if filters:
|
||||
for key, value in filters.iteritems():
|
||||
for key, value in iteritems(filters):
|
||||
column = getattr(model, key, None)
|
||||
if column:
|
||||
query = query.filter(column.in_(value))
|
||||
for _name, hooks in self._model_query_hooks.get(model,
|
||||
{}).iteritems():
|
||||
for _name, hooks in iteritems(
|
||||
self._model_query_hooks.get(model, {})):
|
||||
result_filter = hooks.get('result_filters', None)
|
||||
if isinstance(result_filter, basestring):
|
||||
result_filter = getattr(self, result_filter, None)
|
||||
|
@ -198,4 +197,4 @@ class CommonDbMixin(object):
|
|||
"""
|
||||
columns = [c.name for c in model.__table__.columns]
|
||||
return dict((k, v) for (k, v) in
|
||||
data.iteritems() if k in columns)
|
||||
iteritems(data) if k in columns)
|
||||
|
|
|
@ -181,7 +181,7 @@ def _build_match_rule(action, target):
|
|||
validate = attribute.get('validate')
|
||||
if (validate and any([k.startswith('type:dict') and v
|
||||
for (k, v) in
|
||||
validate.iteritems()])):
|
||||
six.iteritems(validate)])):
|
||||
attr_rule = policy.AndCheck(
|
||||
[attr_rule, _build_subattr_match_rule(
|
||||
attribute_name, attribute,
|
||||
|
|
|
@ -28,6 +28,7 @@ import fixtures
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_messaging import conffixture as messaging_conffixture
|
||||
from six import iteritems
|
||||
import testtools
|
||||
|
||||
from tacker.common import config
|
||||
|
@ -199,7 +200,7 @@ class BaseTestCase(testtools.TestCase):
|
|||
test by the fixtures cleanup process.
|
||||
"""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in kw.iteritems():
|
||||
for k, v in iteritems(kw):
|
||||
CONF.set_override(k, v, group)
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
|
@ -538,7 +538,7 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
|
|||
output_dict = res['networks'][0]
|
||||
input_dict['shared'] = False
|
||||
self.assertEqual(len(input_dict), len(output_dict))
|
||||
for k, v in input_dict.iteritems():
|
||||
for k, v in six.iteritems(input_dict):
|
||||
self.assertEqual(v, output_dict[k])
|
||||
else:
|
||||
# expect no results
|
||||
|
@ -1122,7 +1122,8 @@ class SubresourceTest(base.BaseTestCase):
|
|||
|
||||
# Save the global RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
|
||||
for resource, attrs in six.iteritems(
|
||||
attributes.RESOURCE_ATTRIBUTE_MAP):
|
||||
self.saved_attr_map[resource] = attrs.copy()
|
||||
|
||||
self.config_parse()
|
||||
|
@ -1296,7 +1297,8 @@ class ExtensionTestCase(base.BaseTestCase):
|
|||
|
||||
# Save the global RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
|
||||
for resource, attrs in six.iteritems(
|
||||
attributes.RESOURCE_ATTRIBUTE_MAP):
|
||||
self.saved_attr_map[resource] = attrs.copy()
|
||||
|
||||
# Create the default configurations
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
Unit tests for extension extended attribute
|
||||
"""
|
||||
|
||||
from six import iteritems
|
||||
import webob.exc as webexc
|
||||
|
||||
import tacker
|
||||
|
@ -58,7 +59,7 @@ class ExtensionExtendedAttributeTestCase(base.BaseTestCase):
|
|||
self._tenant_id = "8c70909f-b081-452d-872b-df48e6c355d1"
|
||||
# Save the global RESOURCE_ATTRIBUTE_MAP
|
||||
self.saved_attr_map = {}
|
||||
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
|
||||
for resource, attrs in iteritems(attributes.RESOURCE_ATTRIBUTE_MAP):
|
||||
self.saved_attr_map[resource] = attrs.copy()
|
||||
# Add the resources to the global attribute map
|
||||
# This is done here as the setup process won't
|
||||
|
|
|
@ -19,6 +19,7 @@ import time
|
|||
|
||||
from heatclient import exc as heatException
|
||||
from oslo_config import cfg
|
||||
from six import iteritems
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.utils import yamlparser
|
||||
from translator.hot.tosca_translator import TOSCATranslator
|
||||
|
@ -131,7 +132,7 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
|
|||
|
||||
@log.log
|
||||
def _update_params(self, original, paramvalues, match=False):
|
||||
for key, value in original.iteritems():
|
||||
for key, value in iteritems(original):
|
||||
if not isinstance(value, dict) or 'get_input' not in str(value):
|
||||
pass
|
||||
elif isinstance(value, dict):
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
import time
|
||||
|
||||
|
||||
from keystoneclient import auth as ks_auth
|
||||
from keystoneclient.auth.identity import v2 as v2_auth
|
||||
from keystoneclient import session as ks_session
|
||||
from oslo_config import cfg
|
||||
from six import iteritems
|
||||
|
||||
from tacker.api.v1 import attributes
|
||||
from tacker.i18n import _LE, _LW
|
||||
|
@ -139,8 +141,8 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver):
|
|||
port_data['fixed_ips'] = [{'subnet_id': subnet_id}]
|
||||
|
||||
# See api.v2.base.prepare_request_body()
|
||||
for attr, attr_vals in attributes.RESOURCE_ATTRIBUTE_MAP[
|
||||
attributes.PORTS].iteritems():
|
||||
for attr, attr_vals in iteritems(attributes.RESOURCE_ATTRIBUTE_MAP[
|
||||
attributes.PORTS]):
|
||||
if not attr_vals.get('allow_post', False):
|
||||
continue
|
||||
if attr in port_data:
|
||||
|
|
|
@ -20,6 +20,7 @@ from tacker.common import utils
|
|||
from tacker.extensions import vnfm
|
||||
from tacker.openstack.common import log as logging
|
||||
|
||||
from six import iteritems
|
||||
from toscaparser.properties import Property
|
||||
from toscaparser.utils import yamlparser
|
||||
|
||||
|
@ -127,15 +128,15 @@ def get_mgmt_ports(tosca):
|
|||
|
||||
@log.log
|
||||
def add_resources_tpl(heat_dict, hot_res_tpl):
|
||||
for res, res_dict in hot_res_tpl.iteritems():
|
||||
for vdu, vdu_dict in res_dict.iteritems():
|
||||
for res, res_dict in iteritems(hot_res_tpl):
|
||||
for vdu, vdu_dict in iteritems(res_dict):
|
||||
res_name = vdu + "_" + res
|
||||
heat_dict["resources"][res_name] = {
|
||||
"type": HEAT_RESOURCE_MAP[res],
|
||||
"properties": {}
|
||||
}
|
||||
|
||||
for prop, val in vdu_dict.iteritems():
|
||||
for prop, val in iteritems(vdu_dict):
|
||||
heat_dict["resources"][res_name]["properties"][prop] = val
|
||||
heat_dict["resources"][vdu]["properties"][res] = {
|
||||
"get_resource": res_name
|
||||
|
@ -217,7 +218,7 @@ def get_flavor_dict(template, flavor_extra_input=None):
|
|||
flavor_dict[nt.name] = {}
|
||||
properties = nt.get_capabilities()["nfv_compute"].get_properties()
|
||||
for prop, (hot_prop, default, unit) in \
|
||||
FLAVOR_PROPS.iteritems():
|
||||
iteritems(FLAVOR_PROPS):
|
||||
hot_prop_val = (properties[prop].value
|
||||
if properties.get(prop, None) else None)
|
||||
if unit and hot_prop_val:
|
||||
|
@ -282,7 +283,7 @@ def get_image_dict(template):
|
|||
if not vdu.entity_tpl.get("artifacts", None):
|
||||
continue
|
||||
artifacts = vdu.entity_tpl["artifacts"]
|
||||
for name, artifact in artifacts.iteritems():
|
||||
for name, artifact in iteritems(artifacts):
|
||||
if ('type' in artifact.keys() and
|
||||
artifact["type"] == IMAGE):
|
||||
if 'file' not in artifact.keys():
|
||||
|
@ -298,7 +299,7 @@ def get_image_dict(template):
|
|||
|
||||
def get_resources_dict(template, flavor_extra_input=None):
|
||||
res_dict = dict()
|
||||
for res, method in OS_RESOURCES.iteritems():
|
||||
for res, method in iteritems(OS_RESOURCES):
|
||||
res_method = getattr(sys.modules[__name__], method)
|
||||
if res is 'flavor':
|
||||
res_dict[res] = res_method(template, flavor_extra_input)
|
||||
|
|
|
@ -429,7 +429,7 @@ class XMLDictSerializer(DictSerializer):
|
|||
root_key = constants.VIRTUAL_ROOT_KEY
|
||||
root_value = None
|
||||
else:
|
||||
link_keys = [k for k in data.iterkeys() or []
|
||||
link_keys = [k for k in data or []
|
||||
if k.endswith('_links')]
|
||||
if link_keys:
|
||||
links = data.pop(link_keys[0], None)
|
||||
|
@ -949,7 +949,7 @@ class Debug(Middleware):
|
|||
resp = req.get_response(self.application)
|
||||
|
||||
print(("*" * 40) + " RESPONSE HEADERS")
|
||||
for (key, value) in resp.headers.iteritems():
|
||||
for (key, value) in six.iteritems(resp.headers):
|
||||
print(key, "=", value)
|
||||
print()
|
||||
|
||||
|
|
Loading…
Reference in New Issue