Use the six library for compatability

Replace dict.iteritems() with six.iteritems(dict)
Import six for StringIO
Import urlutils for urlencode

Partial implement: blueprint py33-support

Change-Id: Ieae1299915168ef10ff54e0a9e9a346350e9d1fb
This commit is contained in:
Kui Shi
2013-10-20 16:04:21 +08:00
parent e274a23dfc
commit d07ec04e19
3 changed files with 8 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ Base utilities to build API operation managers and objects on top of.
"""
import copy
import six
# Python 2.4 compat
@@ -86,7 +87,7 @@ class Resource(object):
self._loaded = loaded
def _add_details(self, info):
for (k, v) in info.iteritems():
for (k, v) in six.iteritems(info):
setattr(self, k, v)
def __getattr__(self, k):

View File

@@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import cStringIO
import httplib2
import os
import re
import six
import sys
import urllib2
import yaml
@@ -64,7 +64,7 @@ class TestCase(testtools.TestCase):
def shell_error(self, argstr, error_match):
orig = sys.stderr
try:
sys.stderr = cStringIO.StringIO()
sys.stderr = six.StringIO()
_shell = heatclient.shell.HeatShell()
_shell.main(argstr.split())
except Exception as e:
@@ -224,7 +224,7 @@ class ShellTest(TestCase):
def shell(self, argstr):
orig = sys.stdout
try:
sys.stdout = cStringIO.StringIO()
sys.stdout = six.StringIO()
_shell = heatclient.shell.HeatShell()
_shell.main(argstr.split())
except SystemExit:
@@ -654,7 +654,7 @@ class ShellEnvironmentTest(TestCase):
fields = {'files': {}}
if url:
self.m.StubOutWithMock(urllib2, 'urlopen')
urllib2.urlopen(url).AndReturn(cStringIO.StringIO(content))
urllib2.urlopen(url).AndReturn(six.StringIO(content))
self.m.ReplayAll()
v1shell._resolve_environment_urls(fields, env_base_url, jenv)

View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.common import base
@@ -72,7 +72,7 @@ class StackManager(base.Manager):
absolute_limit = kwargs.get('limit')
def paginate(qp, seen=0):
url = '/stacks?%s' % urllib.urlencode(qp)
url = '/stacks?%s' % urlutils.urlencode(qp)
stacks = self._list(url, "stacks")
for stack in stacks: