def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,<EOL>source_address=None):
host, port = address<EOL>err = None<EOL>for res in getaddrinfo(host, port, <NUM_LIT:0>, SOCK_STREAM):<EOL><INDENT>af, socktype, proto, canonname, sa = res<EOL>sock = None<EOL>try:<EOL><INDENT>sock = socket(af, socktype, proto)<EOL>if timeout is not _GLOBAL_DEFAULT_TIMEOUT:<EOL><INDENT>sock.settimeout(timeout)<EOL><DEDENT>if source_address:<EOL><INDENT>sock.bind(source_address)<EOL><DEDENT>sock.connect(sa)<EOL>return sock<EOL><DEDENT>except error as _:<EOL><INDENT>err = _<EOL>if sock is not None:<EOL><INDENT>sock.close()<EOL><DEDENT><DEDENT><DEDENT>if err is not None:<EOL><INDENT>raise err<EOL><DEDENT>else:<EOL><INDENT>raise error("<STR_LIT>")<EOL><DEDENT>
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.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    An host of '' or port 0 tells the OS to use the default.