(url)
return urlunparse(url_parts)
Parses the given URL, resolves the hostname to an IP address
        and returns a new URL with the resolved IP address. This speeds
        up things big time on Mac OS X where an IP lookup would be
        performed for every XML-RPC call otherwise.
Parses the given URL, resolves the hostname to an IP address
        and returns a new URL with the resolved IP address. This speeds
        up things big time on Mac OS X where an IP lookup would be
        performed for every XML-RPC call otherwise.
Parses the given URL resolves the hostname to an IP address and returns a new URL with the resolved IP address . This speeds up things big time on Mac OS X where an IP lookup would be performed for every XML - RPC call otherwise .
def _resolve_hostname(url):
        """Parses the given URL, resolves the hostname to an IP address
        and returns a new URL with the resolved IP address. This speeds
        up things big time on Mac OS X where an IP lookup would be
        performed for every XML-RPC call otherwise."""
        from urllib.parse import urlparse, urlunparse
        import re

        url_parts = urlparse(url)
        hostname = url_parts.netloc
        if re.match("[0-9.:]+$", hostname):
            # the hostname is already an IP address, possibly with a port
            return url

        from socket import gethostbyname

        if ":" in hostname:
            hostname = hostname[0 : hostname.index(":")]
        hostname = gethostbyname(hostname)
        if url_parts.port is not None:
            hostname = "%s:%d" % (hostname, url_parts.port)
        url_parts = list(url_parts)
        url_parts[1] = hostname
        return urlunparse(url_parts)
def _resolve_hostname ( url ) : from urllib . parse import urlparse , urlunparse import re url_parts = urlparse ( url ) hostname = url_parts . netloc if re . match ( "[0-9.:]+$" , hostname ) : # the hostname is already an IP address, possibly with a port return url from socket import gethostbyname if ":" in hostname : hostname = hostname [ 0 : hostname . index ( ":" ) ] hostname = gethostbyname ( hostname ) if url_parts . port is not None : hostname = "%s:%d" % ( hostname , url_parts . port ) url_parts = list ( url_parts ) url_parts [ 1 ] = hostname return urlunparse ( url_parts )