ansible/ansible — pull request #8898 by sivel (2014-09-05 15:57:59+00:00)
Title: Support python < 2.6 in urls.py

`module_utils/urls.py` uses `socket.create_connection` for HTTPS connections, however `socket.create_connection` was not added until python 2.6. This results in tracebacks on Python < 2.6 such as RHEL 5.

```
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 2210, in ?
main()
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 222, in main
tmpsrc, info = url_get(module, url, dest, use_proxy, last_mod_time, force)
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 146, in url_get
rsp, info = fetch_url(module, url, use_proxy=use_proxy, force=force, last_mod_time=last_mod_time)
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 2196, in fetch_url
r = urllib2.urlopen(request, None)
File "/usr/lib64/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib64/python2.4/urllib2.py", line 358, in open
response = self._open(req, data)
File "/usr/lib64/python2.4/urllib2.py", line 376, in _open
'_open', req)
File "/usr/lib64/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 1861, in https_open
return self.do_open(CustomHTTPSConnection, req)
File "/usr/lib64/python2.4/urllib2.py", line 1089, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib64/python2.4/httplib.py", line 810, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.4/httplib.py", line 833, in _send_request
self.endheaders()
File "/usr/lib64/python2.4/httplib.py", line 804, in endheaders
self._send_output()
File "/usr/lib64/python2.4/httplib.py", line 685, in _send_output
self.send(msg)
File "/usr/lib64/python2.4/httplib.py", line 652, in send
self.connect()
File "/home/sivel/.ansible/tmp/ansible-tmp-1409930019.36-92123499720727/get_url", line 1852, in connect
sock = socket.create_connection((self.host, self.port), self.timeout)
AttributeError: 'module' object has no attribute 'create_connection'
```

This pull request backports `create_connection` from python 2.7 (not python 2.6 due to create_connection being enhanced in python 2.7) and made compatible with python < 2.7.

Additionally an `__init__` method was added to `CustomHTTPSConnection` to ensure that we have the required instance attributes for python < 2.6.

I have tested these changes with Python 2.4 (RHEL5), Python 2.6 (RHEL5) as well as Python 2.7 (Mac OS X 10.9)