Commit cff4ad88 authored by Denis Bilenko's avatar Denis Bilenko

socket.py: add create_connection_ssl, similar to create_connection

parent 695f4397
......@@ -467,6 +467,35 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
raise error, msg
def create_connection_ssl(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
*timeout* parameter will set the timeout on the socket instance
before attempting to connect. If no *timeout* is supplied, the
global default timeout setting returned by :func:`getdefaulttimeout`
is used.
"""
msg = "getaddrinfo returns an empty list"
host, port = address
for res in getaddrinfo(host, port, 0, _socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
_sock = _original_socket(af, socktype, proto)
sock = wrap_ssl000(_sock)
if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
sock.connect(sa)
return sock
except error, msg:
if sock is not None:
sock.close()
raise error, msg
# get rid of this
def wrap_ssl000(sock, keyfile=None, certfile=None):
from OpenSSL import SSL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment