From b4ea550ba7cd7d322739fcfae8b8af7ae191c49b Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 12 Jun 2013 08:28:17 -0500 Subject: [PATCH] python3: fix imports compatibility Python3 reorganized the standard library and moved several functions to different modules. Six provides a consistent interface to them through the fake six.moves module. However, the urlparse, urllib2, etc modules have been combined into one module which Six does not support so do it the old fashioned way. Change-Id: Ieb7cc7ee2a4a97807873cfe2fc3fa0a5cf3c3980 Signed-off-by: Chuck Short --- cinderclient/client.py | 7 ++++++- cinderclient/tests/test_shell.py | 4 ++-- cinderclient/tests/test_utils.py | 5 +++-- cinderclient/tests/v1/fakes.py | 5 ++++- cinderclient/tests/v2/fakes.py | 5 ++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cinderclient/client.py b/cinderclient/client.py index 755ffcb83..5f3404bd6 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -21,7 +21,12 @@ OpenStack Client interface. Handles the REST calls and responses. import logging import os -import urlparse + +try: + import urlparse +except ImportError: + import urllib.parse as urlparse + try: from eventlet import sleep except ImportError: diff --git a/cinderclient/tests/test_shell.py b/cinderclient/tests/test_shell.py index c3a195fb2..d6ef42584 100644 --- a/cinderclient/tests/test_shell.py +++ b/cinderclient/tests/test_shell.py @@ -1,8 +1,8 @@ -import cStringIO import re import sys import fixtures +from six import moves from testtools import matchers from cinderclient import exceptions @@ -29,7 +29,7 @@ class ShellTest(utils.TestCase): def shell(self, argstr): orig = sys.stdout try: - sys.stdout = cStringIO.StringIO() + sys.stdout = moves.StringIO() _shell = cinderclient.shell.OpenStackCinderShell() _shell.main(argstr.split()) except SystemExit: diff --git a/cinderclient/tests/test_utils.py b/cinderclient/tests/test_utils.py index fc6128536..8df482d18 100644 --- a/cinderclient/tests/test_utils.py +++ b/cinderclient/tests/test_utils.py @@ -1,7 +1,8 @@ import collections -import StringIO import sys +from six import moves + from cinderclient import exceptions from cinderclient import utils from cinderclient import base @@ -82,7 +83,7 @@ class CaptureStdout(object): """Context manager for capturing stdout from statments in its's block.""" def __enter__(self): self.real_stdout = sys.stdout - self.stringio = StringIO.StringIO() + self.stringio = moves.StringIO() sys.stdout = self.stringio return self diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index 411c5e191..a71f50247 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -13,7 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urlparse +try: + import urlparse +except ImportError: + import urllib.parse as urlparse from cinderclient import client as base_client from cinderclient.tests import fakes diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index f90ace363..28cb20a8a 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urlparse +try: + import urlparse +except ImportError: + import urllib.parse as urlparse from cinderclient import client as base_client from cinderclient.tests import fakes