From eea574a78adc54242a97ac3b5ed0b8deeea754bf Mon Sep 17 00:00:00 2001 From: Lokesh S Date: Thu, 28 Jul 2016 12:10:12 +0000 Subject: [PATCH] Py3: Fixes eventlet ImportError: No module named urllib2 Python3: from eventlet.green.urllib import request Python2: from eventlet.green import urllib2 Change-Id: Ib38865e0b6a8f076b8a54de4fae221d49f315c91 --- doc/source/development_middleware.rst | 6 +++++- swift/cli/recon.py | 8 +++++++- swift/common/internal_client.py | 7 ++++++- test/unit/cli/test_recon.py | 8 +++++++- test/unit/common/test_internal_client.py | 6 +++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/doc/source/development_middleware.rst b/doc/source/development_middleware.rst index 9612be9822..b1b57d408f 100644 --- a/doc/source/development_middleware.rst +++ b/doc/source/development_middleware.rst @@ -81,7 +81,11 @@ presented below:: from swift.proxy.controllers.base import get_container_info from eventlet import Timeout - from eventlet.green import urllib2 + import six + if six.PY3: + from eventlet.green.urllib import request as urllib2 + else: + from eventlet.green import urllib2 # x-container-sysmeta-webhook SYSMETA_WEBHOOK = get_sys_meta_prefix('container') + 'webhook' diff --git a/swift/cli/recon.py b/swift/cli/recon.py index cd96c60c8f..35fa07a318 100644 --- a/swift/cli/recon.py +++ b/swift/cli/recon.py @@ -17,7 +17,7 @@ from __future__ import print_function -from eventlet.green import urllib2, socket +from eventlet.green import socket from six.moves.urllib.parse import urlparse from swift.common.utils import SWIFT_CONF_FILE from swift.common.ring import Ring @@ -28,8 +28,14 @@ import json import optparse import time import sys +import six import os +if six.PY3: + from eventlet.green.urllib import request as urllib2 +else: + from eventlet.green import urllib2 + def seconds2timeunit(seconds): elapsed = seconds diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index 990fc405e3..6eda3924ce 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -14,7 +14,7 @@ # limitations under the License. from eventlet import sleep, Timeout -from eventlet.green import httplib, socket, urllib2 +from eventlet.green import httplib, socket import json import six from six.moves import range @@ -32,6 +32,11 @@ from swift.common.swob import Request from swift.common.utils import quote from swift.common.wsgi import loadapp, pipeline_property +if six.PY3: + from eventlet.green.urllib import request as urllib2 +else: + from eventlet.green import urllib2 + class UnexpectedResponse(Exception): """ diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py index 4532c680ba..babe8fb4fa 100644 --- a/test/unit/cli/test_recon.py +++ b/test/unit/cli/test_recon.py @@ -22,8 +22,9 @@ import time import unittest import shutil import sys +import six -from eventlet.green import urllib2, socket +from eventlet.green import socket from six import StringIO from six.moves import urllib @@ -34,6 +35,11 @@ from swift.common.ring import utils as ring_utils from swift.common.storage_policy import StoragePolicy, POLICIES from test.unit import patch_policies +if six.PY3: + from eventlet.green.urllib import request as urllib2 +else: + from eventlet.green import urllib2 + class TestHelpers(unittest.TestCase): def test_seconds2timeunit(self): diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index 2d4c747179..ef6002b715 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -25,7 +25,6 @@ from six import StringIO from six.moves import range from six.moves.urllib.parse import quote from test.unit import FakeLogger -from eventlet.green import urllib2 from swift.common import exceptions, internal_client, swob from swift.common.header_key_dict import HeaderKeyDict from swift.common.storage_policy import StoragePolicy @@ -33,6 +32,11 @@ from swift.common.storage_policy import StoragePolicy from test.unit import with_tempdir, write_fake_ring, patch_policies from test.unit.common.middleware.helpers import FakeSwift +if six.PY3: + from eventlet.green.urllib import request as urllib2 +else: + from eventlet.green import urllib2 + class FakeConn(object): def __init__(self, body=None):