Import from urllib and not url (#25102)

* Import from urllib and not url

In Python 3, the correct way to import
urlparse is through urllib.parse.

* Use six module to import urlparse

Import urlparse from ansible.module_utils.six.
This way, the import statement is compatible both
with Python 3 and Python 2.

* Fix urlparse import using six module

The correct import is:
from six.moves.urllib.parse import urlparse

* Import six from ansible.compat

* Import from six.moves. Don't make six global.

Prevent code smell by not making six available
in the global namespace and instead importing from
one of its subpackages.
pull/25208/head
Esteban Echeverry 8 years ago committed by Brian Coca
parent e67cdd448e
commit b7662f7e5b

@ -27,6 +27,9 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from ansible.module_utils.urls import generic_urlparse
from ansible.module_utils.six.moves.urllib.parse import urlparse
try: try:
import json import json
except ImportError: except ImportError:
@ -51,13 +54,6 @@ class UnixHTTPConnection(HTTPConnection):
sock.connect(self.path) sock.connect(self.path)
self.sock = sock self.sock = sock
from ansible.module_utils.urls import generic_urlparse
try:
from urlparse import urlparse
except ImportError:
# Python 3
from url.parse import urlparse
class LXDClientException(Exception): class LXDClientException(Exception):
def __init__(self, msg, **kwargs): def __init__(self, msg, **kwargs):
self.msg = msg self.msg = msg

Loading…
Cancel
Save