Replace six.iteritems() with .items()

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 be more readable.

In py2, the performance about list should be negligible

Change-Id: I972b6eb73620eea0cae8b1e0ed9df5f80213bf3d
This commit is contained in:
WangBinbin 2017-03-14 05:47:12 +08:00
parent fce80a3991
commit b86e7a0609
4 changed files with 6 additions and 11 deletions

View File

@ -23,7 +23,6 @@ from pecan import expose
from pecan import request from pecan import request
import restcomm import restcomm
import six
from kingbird.common import exceptions from kingbird.common import exceptions
from kingbird.common.i18n import _ from kingbird.common.i18n import _
@ -215,7 +214,7 @@ class QuotaManagerController(object):
if CONF.use_default_quota_class: if CONF.use_default_quota_class:
default_quotas = db_api.quota_class_get_default(context) default_quotas = db_api.quota_class_get_default(context)
for resource, default in six.iteritems(config_defaults): for resource, default in config_defaults.items():
# get rid of the 'quota_' prefix # get rid of the 'quota_' prefix
resource_name = resource[6:] resource_name = resource[6:]
if default_quotas: if default_quotas:

View File

@ -18,8 +18,6 @@ import pecan
from pecan import expose from pecan import expose
from pecan import request from pecan import request
import six
from kingbird.api.controllers import restcomm from kingbird.api.controllers import restcomm
from kingbird.common import consts from kingbird.common import consts
from kingbird.common import exceptions from kingbird.common import exceptions
@ -94,7 +92,7 @@ class QuotaClassSetController(object):
utils.validate_quota_limits(quota_class_set) utils.validate_quota_limits(quota_class_set)
for key, value in six.iteritems(quota_class_set): for key, value in quota_class_set.items():
try: try:
db_api.quota_class_update(context, class_name, key, value) db_api.quota_class_update(context, class_name, key, value)
except exceptions.QuotaClassNotFound: except exceptions.QuotaClassNotFound:

View File

@ -12,7 +12,6 @@
# implied. # implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import six
import oslo_messaging import oslo_messaging
@ -23,7 +22,7 @@ class Mapping(object):
def __init__(self, mapping): def __init__(self, mapping):
self.direct_mapping = mapping self.direct_mapping = mapping
self.reverse_mapping = {} self.reverse_mapping = {}
for key, value in six.iteritems(mapping): for key, value in mapping.items():
self.reverse_mapping[value] = key self.reverse_mapping[value] = key
_SINGLETON_MAPPING = Mapping({ _SINGLETON_MAPPING = Mapping({
@ -38,7 +37,7 @@ class KingbirdSerializer(oslo_messaging.Serializer):
def serialize_entity(self, context, entity): def serialize_entity(self, context, entity):
if isinstance(entity, dict): if isinstance(entity, dict):
for key, value in six.iteritems(entity): for key, value in entity.items():
entity[key] = self.serialize_entity(context, value) entity[key] = self.serialize_entity(context, value)
elif isinstance(entity, list): elif isinstance(entity, list):
@ -55,7 +54,7 @@ class KingbirdSerializer(oslo_messaging.Serializer):
def deserialize_entity(self, context, entity): def deserialize_entity(self, context, entity):
if isinstance(entity, dict): if isinstance(entity, dict):
for key, value in six.iteritems(entity): for key, value in entity.items():
entity[key] = self.deserialize_entity(context, value) entity[key] = self.deserialize_entity(context, value)
elif isinstance(entity, list): elif isinstance(entity, list):

View File

@ -13,7 +13,6 @@
import datetime import datetime
from oslo_config import cfg from oslo_config import cfg
import six
import sqlalchemy import sqlalchemy
CLASS_NAME = 'default' CLASS_NAME = 'default'
@ -40,7 +39,7 @@ def upgrade(migrate_engine):
# Set default quota limits # Set default quota limits
qci = quota_classes.insert() qci = quota_classes.insert()
for resource, default in six.iteritems(CONF.kingbird_global_limit): for resource, default in CONF.kingbird_global_limit.items():
qci.execute({'created_at': CREATED_AT, qci.execute({'created_at': CREATED_AT,
'class_name': CLASS_NAME, 'class_name': CLASS_NAME,
'resource': resource[6:], 'resource': resource[6:],