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.
This commit is contained in:
Esteban Echeverry 2017-05-31 14:27:22 -05:00 committed by Brian Coca
parent e67cdd448e
commit b7662f7e5b

View file

@ -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