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

View File

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

View File

@@ -16,6 +16,8 @@
import os import os
import six
from keystoneclient.common import cms from keystoneclient.common import cms
from keystoneclient.openstack.common import jsonutils from keystoneclient.openstack.common import jsonutils
from keystoneclient.openstack.common import timeutils from keystoneclient.openstack.common import timeutils
@@ -295,4 +297,4 @@ TOKEN_RESPONSES = {
JSON_TOKEN_RESPONSES = dict([(k, jsonutils.dumps(v)) for k, v in 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. # under the License.
import httpretty import httpretty
import six
import testtools import testtools
from testtools import matchers from testtools import matchers
@@ -194,10 +195,10 @@ class BasicRequestTests(testtools.TestCase):
self.request(headers=headers) 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) 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, self.assertThat(self.logger.debug_log,
matchers.Contains('-H "%s: %s"' % header)) matchers.Contains('-H "%s: %s"' % header))

View File

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

View File

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