From b7662f7e5bdb55093f22f672d2c71ab9813ad96d Mon Sep 17 00:00:00 2001 From: Esteban Echeverry Date: Wed, 31 May 2017 14:27:22 -0500 Subject: [PATCH] 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. --- lib/ansible/module_utils/lxd.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/lxd.py b/lib/ansible/module_utils/lxd.py index f3464c10e18..e3eb078729a 100644 --- a/lib/ansible/module_utils/lxd.py +++ b/lib/ansible/module_utils/lxd.py @@ -27,6 +27,9 @@ # 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. +from ansible.module_utils.urls import generic_urlparse +from ansible.module_utils.six.moves.urllib.parse import urlparse + try: import json except ImportError: @@ -51,13 +54,6 @@ class UnixHTTPConnection(HTTPConnection): sock.connect(self.path) 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): def __init__(self, msg, **kwargs): self.msg = msg