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 <chuck.short@canonical.com>
This commit is contained in:
Chuck Short 2013-06-12 08:28:17 -05:00
parent 70f95192a9
commit b4ea550ba7
5 changed files with 19 additions and 7 deletions

@ -21,7 +21,12 @@ OpenStack Client interface. Handles the REST calls and responses.
import logging import logging
import os import os
import urlparse
try:
import urlparse
except ImportError:
import urllib.parse as urlparse
try: try:
from eventlet import sleep from eventlet import sleep
except ImportError: except ImportError:

@ -1,8 +1,8 @@
import cStringIO
import re import re
import sys import sys
import fixtures import fixtures
from six import moves
from testtools import matchers from testtools import matchers
from cinderclient import exceptions from cinderclient import exceptions
@ -29,7 +29,7 @@ class ShellTest(utils.TestCase):
def shell(self, argstr): def shell(self, argstr):
orig = sys.stdout orig = sys.stdout
try: try:
sys.stdout = cStringIO.StringIO() sys.stdout = moves.StringIO()
_shell = cinderclient.shell.OpenStackCinderShell() _shell = cinderclient.shell.OpenStackCinderShell()
_shell.main(argstr.split()) _shell.main(argstr.split())
except SystemExit: except SystemExit:

@ -1,7 +1,8 @@
import collections import collections
import StringIO
import sys import sys
from six import moves
from cinderclient import exceptions from cinderclient import exceptions
from cinderclient import utils from cinderclient import utils
from cinderclient import base from cinderclient import base
@ -82,7 +83,7 @@ class CaptureStdout(object):
"""Context manager for capturing stdout from statments in its's block.""" """Context manager for capturing stdout from statments in its's block."""
def __enter__(self): def __enter__(self):
self.real_stdout = sys.stdout self.real_stdout = sys.stdout
self.stringio = StringIO.StringIO() self.stringio = moves.StringIO()
sys.stdout = self.stringio sys.stdout = self.stringio
return self return self

@ -13,7 +13,10 @@
# 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 urlparse try:
import urlparse
except ImportError:
import urllib.parse as urlparse
from cinderclient import client as base_client from cinderclient import client as base_client
from cinderclient.tests import fakes from cinderclient.tests import fakes

@ -12,7 +12,10 @@
# 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 urlparse try:
import urlparse
except ImportError:
import urllib.parse as urlparse
from cinderclient import client as base_client from cinderclient import client as base_client
from cinderclient.tests import fakes from cinderclient.tests import fakes