Fixed import of urlencode and pathname2url from urllib for python3 (#24424)

This commit is contained in:
Michael
2017-05-19 17:22:16 +00:00
committed by Matt Martz
parent 98a8b967d2
commit b65ebf3519
26 changed files with 66 additions and 69 deletions

View File

@@ -110,7 +110,7 @@ EXAMPLES = '''
tags: tag1,tag2,tag3
'''
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
# ===========================================
# Module execution.
@@ -185,7 +185,7 @@ def main():
module.exit_json(changed=False)
# Send the data to Flowdock
data = urllib.urlencode(params)
data = urlencode(params)
response, info = fetch_url(module, url, data=data)
if info['status'] != 200:
module.fail_json(msg="unable to send msg: %s" % info['msg'])

View File

@@ -69,7 +69,7 @@ EXAMPLES = '''
message=deployed {{ target }}
'''
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
BASE_URL = 'https://grove.io/api/notice/%s/'
@@ -85,7 +85,7 @@ def do_notify_grove(module, channel_token, service, message, url=None, icon_url=
if icon_url is not None:
my_data['icon_url'] = icon_url
data = urllib.urlencode(my_data)
data = urlencode(my_data)
response, info = fetch_url(module, my_url, data=data)
if info['status'] != 200:
module.fail_json(msg="failed to send notification: %s" % info['msg'])

View File

@@ -103,15 +103,17 @@ EXAMPLES = '''
# HipChat module specific support methods.
#
import urllib
try:
import json
except ImportError:
import simplejson as json
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.six.moves.urllib.request import pathname2url
from ansible.module_utils.urls import fetch_url
DEFAULT_URI = "https://api.hipchat.com/v1"
@@ -135,7 +137,7 @@ def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
params['notify'] = int(notify)
url = api + MSG_URI_V1 + "?auth_token=%s" % (token)
data = urllib.urlencode(params)
data = urlencode(params)
if module.check_mode:
# In check mode, exit before actually sending the message
@@ -162,7 +164,7 @@ def send_msg_v2(module, token, room, msg_from, msg, msg_format='text',
POST_URL = api + NOTIFY_URI_V2
url = POST_URL.replace('{id_or_name}', urllib.pathname2url(room))
url = POST_URL.replace('{id_or_name}', pathname2url(room))
data = json.dumps(body)
if module.check_mode:

View File

@@ -76,7 +76,7 @@ EXAMPLES = """
delegate_to: localhost
"""
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
NEXMO_API = 'https://rest.nexmo.com/sms/json'
@@ -92,7 +92,7 @@ def send_msg(module):
}
for number in module.params.get('dest'):
msg['to'] = number
url = "%s?%s" % (NEXMO_API, urllib.urlencode(msg))
url = "%s?%s" % (NEXMO_API, urlencode(msg))
headers = dict(Accept='application/json')
response, info = fetch_url(module, url, headers=headers)

View File

@@ -65,7 +65,7 @@ EXAMPLES = '''
delegate_to: localhost
'''
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
class Pushover(object):
@@ -87,7 +87,7 @@ class Pushover(object):
token=self.token,
priority=priority,
message=msg)
data = urllib.urlencode(options)
data = urlencode(options)
headers = { "Content-type": "application/x-www-form-urlencoded"}
r, info = fetch_url(self.module, url, method='POST', data=data, headers=headers)

View File

@@ -140,7 +140,7 @@ EXAMPLES = '''
# =======================================
# sendgrid module support methods
#
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
try:
import sendgrid
@@ -157,7 +157,7 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses,
AGENT = "Ansible"
data = {'api_user': username, 'api_key':password,
'from':from_address, 'subject': subject, 'text': body}
encoded_data = urllib.urlencode(data)
encoded_data = urlencode(data)
to_addresses_api = ''
for recipient in to_addresses:
if isinstance(recipient, unicode):

View File

@@ -109,7 +109,7 @@ EXAMPLES = '''
# =======================================
# twilio module support methods
#
import urllib
from ansible.module_utils.six.moves.urllib.parse import urlencode
def post_twilio_api(module, account_sid, auth_token, msg, from_number,
@@ -121,7 +121,7 @@ def post_twilio_api(module, account_sid, auth_token, msg, from_number,
data = {'From':from_number, 'To':to_number, 'Body':msg}
if media_url:
data['MediaUrl'] = media_url
encoded_data = urllib.urlencode(data)
encoded_data = urlencode(data)
headers = {'User-Agent': AGENT,
'Content-type': 'application/x-www-form-urlencoded',

View File

@@ -56,8 +56,6 @@ EXAMPLES = '''
msg: install completed
'''
import urllib
try:
import json
except ImportError:
@@ -69,11 +67,12 @@ except ImportError:
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url, ConnectionError
def do_request(module, url, params, headers=None):
data = urllib.urlencode(params)
data = urlencode(params)
if headers is None:
headers = dict()
headers = dict(headers, **{