Python3 compatibility for osa-filters

The urlparse module is renamed to urllib.parse in Python3.

Change-Id: I3dceb2f87e5e0469ab705866163225601686a0af
Implements: blueprint goal-python35
This commit is contained in:
Jimmy McCrory 2017-06-05 12:02:15 -07:00
parent 36ff6fb6da
commit 057ed9a808

View File

@ -18,10 +18,13 @@ import hashlib
import logging import logging
import os import os
import re import re
import urlparse
from ansible import errors from ansible import errors
from jinja2.runtime import Undefined from jinja2.runtime import Undefined
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
"""Filter usage: """Filter usage:
@ -161,7 +164,7 @@ def get_netloc(url):
:returns: ``str`` :returns: ``str``
""" """
try: try:
netloc = urlparse.urlparse(url).netloc netloc = urlparse(url).netloc
except Exception as exp: except Exception as exp:
raise errors.AnsibleFilterError( raise errors.AnsibleFilterError(
'Failed to return the netloc of: "%s"' % str(exp) 'Failed to return the netloc of: "%s"' % str(exp)
@ -194,7 +197,7 @@ def get_netorigin(url):
:returns: ``str`` :returns: ``str``
""" """
try: try:
parsed_url = urlparse.urlparse(url) parsed_url = urlparse(url)
netloc = parsed_url.netloc netloc = parsed_url.netloc
scheme = parsed_url.scheme scheme = parsed_url.scheme
except Exception as exp: except Exception as exp: