python3: Make iteritems py3k compat

Use six.iteritems to replace dictionary.iteritems() on python2 or
dictionary.items() on python3.

Change-Id: I972f065414e22d287bd7e00ab2c6e754f17afb75
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
Chuck Short
2013-10-10 13:20:37 -04:00
parent 4ae816bbff
commit b7b31bf646
6 changed files with 17 additions and 8 deletions

View File

@@ -26,6 +26,7 @@ import logging
import urlparse
import requests
import six
try:
import keyring
@@ -94,7 +95,7 @@ def request(url, method='GET', headers=None, original_ip=None, debug=False,
string_parts.append(' %s' % url)
if headers:
for header in headers.iteritems():
for header in six.iteritems(headers):
string_parts.append(' -H "%s: %s"' % header)
logger.debug("REQ: %s" % "".join(string_parts))

View File

@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from keystoneclient.apiclient import exceptions
from keystoneclient.tests import utils
@@ -21,7 +23,7 @@ class FakeResponse(object):
json_data = {}
def __init__(self, **kwargs):
for key, value in kwargs.iteritems():
for key, value in six.iteritems(kwargs):
setattr(self, key, value)
def json(self):

View File

@@ -16,6 +16,8 @@
import os
import six
from keystoneclient.common import cms
from keystoneclient.openstack.common import jsonutils
from keystoneclient.openstack.common import timeutils
@@ -295,4 +297,4 @@ TOKEN_RESPONSES = {
JSON_TOKEN_RESPONSES = dict([(k, jsonutils.dumps(v)) for k, v in
TOKEN_RESPONSES.iteritems()])
six.iteritems(TOKEN_RESPONSES)])

View File

@@ -15,6 +15,7 @@
# under the License.
import httpretty
import six
import testtools
from testtools import matchers
@@ -194,10 +195,10 @@ class BasicRequestTests(testtools.TestCase):
self.request(headers=headers)
for k, v in headers.iteritems():
for k, v in six.iteritems(headers):
self.assertEqual(httpretty.last_request().headers[k], v)
for header in headers.iteritems():
for header in six.iteritems(headers):
self.assertThat(self.logger.debug_log,
matchers.Contains('-H "%s: %s"' % header))

View File

@@ -17,6 +17,7 @@ import hashlib
import sys
import prettytable
import six
from keystoneclient import exceptions
@@ -74,7 +75,7 @@ def print_dict(d, wrap=0):
pt = prettytable.PrettyTable(['Property', 'Value'],
caching=False, print_empty=False)
pt.aligns = ['l', 'l']
for (prop, value) in d.iteritems():
for (prop, value) in six.iteritems(d):
if value is None:
value = ''
value = _word_wrap(value, max_length=wrap)

View File

@@ -16,6 +16,8 @@
import urllib
import six
from keystoneclient import base
@@ -81,7 +83,7 @@ class TenantManager(base.ManagerWithFind):
"enabled": enabled}}
#Allow Extras Passthru and ensure we don't clobber primary arguments.
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
if k not in params['tenant']:
params['tenant'][k] = v
@@ -131,7 +133,7 @@ class TenantManager(base.ManagerWithFind):
body['tenant']['description'] = description
#Allow Extras Passthru and ensure we don't clobber primary arguments.
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
if k not in body['tenant']:
body['tenant'][k] = v