From aade5234a90bd60b8131f2f97bd43d1d1c3174e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Scala?= Date: Tue, 10 Oct 2017 05:18:09 +0200 Subject: [PATCH] Fix urlparse import for Python3 (#31240) * Fix urlparse import for Python3 in * contrib/inventory/consul_io.py * contrib/inventory/rudder.py * contrib/inventory/windows_azure.py * lib/ansible/module_utils/known_hosts.py * lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py * lib/ansible/modules/cloud/docker/_docker.py * lib/ansible/modules/cloud/ovirt/ovirt_disk.py * lib/ansible/plugins/action/ce_template.py --- contrib/inventory/consul_io.py | 5 +---- contrib/inventory/rudder.py | 8 ++------ contrib/inventory/windows_azure.py | 2 +- lib/ansible/module_utils/known_hosts.py | 7 ++----- .../modules/cloud/centurylink/clc_firewall_policy.py | 4 ++-- lib/ansible/modules/cloud/docker/_docker.py | 6 +----- lib/ansible/modules/cloud/ovirt/ovirt_disk.py | 6 +----- lib/ansible/plugins/action/ce_template.py | 4 ++-- lib/ansible/plugins/lookup/consul_kv.py | 2 +- 9 files changed, 13 insertions(+), 31 deletions(-) diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py index 7dfffb59eb..8f3a104fdf 100755 --- a/contrib/inventory/consul_io.py +++ b/contrib/inventory/consul_io.py @@ -473,10 +473,7 @@ class ConsulConfig(dict): scheme = 'http' if hasattr(self, 'url'): - try: - from urlparse import urlparse - except ImportError: - from urllib.parse import urlparse + from ansible.module_utils.six.moves.urllib.parse import urlparse o = urlparse(self.url) if o.hostname: host = o.hostname diff --git a/contrib/inventory/rudder.py b/contrib/inventory/rudder.py index 5cf16c9761..50f1caeaaa 100755 --- a/contrib/inventory/rudder.py +++ b/contrib/inventory/rudder.py @@ -56,12 +56,8 @@ import argparse import six import httplib2 as http from time import time -from six.moves import configparser - -try: - from urlparse import urlparse -except ImportError: - from urllib.parse import urlparse +from ansible.module_utils.six.moves import configparser +from ansible.module_utils.six.moves.urllib.parse import urlparse try: import json diff --git a/contrib/inventory/windows_azure.py b/contrib/inventory/windows_azure.py index deb17b15f3..5398b54032 100755 --- a/contrib/inventory/windows_azure.py +++ b/contrib/inventory/windows_azure.py @@ -39,7 +39,7 @@ import re import sys import argparse import os -from urlparse import urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse from time import time try: import json diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index ec79f38af5..defdc11b7f 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -30,10 +30,7 @@ import os import hmac import re -try: - import urlparse -except ImportError: - import urllib.parse as urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse try: from hashlib import sha1 @@ -75,7 +72,7 @@ def get_fqdn_and_port(repo_url): fqdn = repo_url.split("/")[0] elif "://" in repo_url: # this should be something we can parse with urlparse - parts = urlparse.urlparse(repo_url) + parts = urlparse(repo_url) # parts[1] will be empty on python2.4 on ssh:// or git:// urls, so # ensure we actually have a parts[1] before continuing. if parts[1] != '': diff --git a/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py b/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py index 57be83606c..b484fc19c9 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py +++ b/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py @@ -166,7 +166,7 @@ firewall_policy: __version__ = '${version}' import os -import urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse from time import sleep from distutils.version import LooseVersion @@ -288,7 +288,7 @@ class ClcFirewallPolicy: :return: policy_id: firewall policy id from creation call """ url = response.get('links')[0]['href'] - path = urlparse.urlparse(url).path + path = urlparse(url).path path_list = os.path.split(path) policy_id = path_list[-1] return policy_id diff --git a/lib/ansible/modules/cloud/docker/_docker.py b/lib/ansible/modules/cloud/docker/_docker.py index 5362ab4ed2..6de13a8b34 100644 --- a/lib/ansible/modules/cloud/docker/_docker.py +++ b/lib/ansible/modules/cloud/docker/_docker.py @@ -516,11 +516,7 @@ EXAMPLES = ''' import json import os import shlex -try: - from urlparse import urlparse -except ImportError: - # python3 - from urllib.parse import urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse try: import docker.client diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_disk.py b/lib/ansible/modules/cloud/ovirt/ovirt_disk.py index 1b2bc6aef5..9927ce6fcf 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_disk.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_disk.py @@ -236,11 +236,7 @@ import ssl from httplib import HTTPSConnection from httplib import IncompleteRead -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse - +from ansible.module_utils.six.moves.urllib.parse import urlparse try: import ovirtsdk4.types as otypes diff --git a/lib/ansible/plugins/action/ce_template.py b/lib/ansible/plugins/action/ce_template.py index adf94eb12f..2c4e1f0ab5 100644 --- a/lib/ansible/plugins/action/ce_template.py +++ b/lib/ansible/plugins/action/ce_template.py @@ -22,7 +22,7 @@ __metaclass__ = type import os import time import glob -import urlparse +from ansible.module_utils.six.moves.urllib.parse import urlsplit from ansible.module_utils._text import to_text from ansible.plugins.action.ce import ActionModule as _ActionModule @@ -72,7 +72,7 @@ class ActionModule(_ActionModule): working_path = self._get_working_path() - if os.path.isabs(src) or urlparse.urlsplit(src).scheme: + if os.path.isabs(src) or urlsplit(src).scheme: source = src else: source = self._loader.path_dwim_relative(working_path, 'templates', src) diff --git a/lib/ansible/plugins/lookup/consul_kv.py b/lib/ansible/plugins/lookup/consul_kv.py index 9b9ecb9ca1..9c5af6864f 100644 --- a/lib/ansible/plugins/lookup/consul_kv.py +++ b/lib/ansible/plugins/lookup/consul_kv.py @@ -61,7 +61,7 @@ RETURN = """ import os import sys -from urlparse import urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase