Return a URL string in which the port is always specified.
12137
private static String normalizeURL(String urlString)
            throws MalformedURLException {
        URL url = new URL(urlString);
        if (url.getPort() == -1) {
            return url.getProtocol() + "://" + url.getHost() + ":"
                    + url.getDefaultPort() + url.getFile()
                    + (url.getRef() != null ? "#" + url.getRef() : "");
        } else {
            return urlString;
        }
    }
1324664
def client_port(self):
        """"""
        address = self._client.getpeername()
        if isinstance(address, tuple):
            return address[1]

        # Maybe a Unix domain socket connection.
        return 0
134470
def port(self, value=None):
        
        if value is not None:
            return URL._mutate(self, port=value)
        return self._tuple.port
255528
def get_normalized_url(url):
        
        scheme, netloc, path, params, query, fragment = urlparse(url)

        # Exclude default port numbers.
        if scheme == 'http' and netloc[-3:] == ':80':
            netloc = netloc[:-3]
        elif scheme == 'https' and netloc[-4:] == ':443':
            netloc = netloc[:-4]
        if scheme not in ('http', 'https'):
            raise ValueError("Unsupported URL %s (%s)." % (url, scheme))

        # Normalized URL excludes params, query, and fragment.
        return urlunparse((scheme, netloc, path, None, None, None))
1230720
def _url(self, uri):
        """"""
        prefix = "{}://{}{}".format(
            self._protocol,
            self.real_connection.host,
            self._port_postfix(),
        )
        return uri.replace(prefix, '', 1)
1055021
def url(self, host):
        """"""
        path = '/'.join(str(v) for v in self._path)
        return 'coaps://{}:5684/{}'.format(host, path)
604995
def get(self):
        """"""
        q = queue.Queue()

        for u, j, k in urls:
            t = threading.Thread(target=self._get_ip_public, args=(q, u, j, k))
            t.daemon = True
            t.start()

        timer = Timer(self.timeout)
        ip = None
        while not timer.finished() and ip is None:
            if q.qsize() > 0:
                ip = q.get()

        return ', '.join(set([x.strip() for x in ip.split(',')]))
189870
private String hostAndPort() {
        int start = url.indexOf("://") + 3;
        int end = url.indexOf("/", start);
        return url.substring(start, end);
    }
750287
def get_url(url):
    
    sub = "{0}.spotilocal.com".format("".join(choices(ascii_lowercase, k=10)))
    return "http://{0}:{1}{2}".format(sub, DEFAULT_PORT, url)
1032094
def port_str(self):
        """"""
        if self.transport is NotSpecified:
            return str(self.port)
        else:
            return "{0}/{1}".format(self.port, self.transport)
1331962
public synchronized UndertowServerEngine retrieveHttpServerEngine(int port)
   {
      UndertowServerEngine engine = null;
      synchronized(portMap)
      {
         engine = portMap.get(port);
      }
      return engine;
   }
612945
def url_to_host_port(url, port=None):
    
    if not url.startswith('http://') and not url.startswith('https://'):
        url = 'http://' + url

    if not port:
        port = RPC_SERVER_PORT

    urlinfo = urllib2.urlparse.urlparse(url)
    hostport = urlinfo.netloc

    parts = hostport.split('@')
    if len(parts) > 2:
        return None, None

    if len(parts) == 2:
        hostport = parts[1]

    parts = hostport.split(':')
    if len(parts) > 2:
        return None, None

    if len(parts) == 2:
        try:
            port = int(parts[1])
            assert 0 < port and port < 65535, 'Invalid port'
        except TypeError:
            return None, None

    return parts[0], port
1177289
def find_available_port():
    
    s = socket.socket()
    s.bind(('localhost', 0))
    _address, port = s.getsockname()
    s.close()
    return port
222153
function getUrl() {
        if (!self.serverUrl) {
            // use the cached version if we already built the string
            self.serverUrl = 'http://127.0.0.1:' + gmeConfig.server.port;
        }

        return self.serverUrl;
    }
1347828
def host_from_uri(uri):
    
    default_ports = {
        'HTTP': '80',
        'HTTPS': '443',
    }

    sch, netloc, path, par, query, fra = urlparse(uri)
    if ':' in netloc:
        netloc, port = netloc.split(':', 1)
    else:
        port = default_ports.get(sch.upper())

    return netloc, port
142837
def select_port(default_port=20128):
    """"""
    import socket
    while True:
        try:
            sock = socket.socket(socket.AF_INET,
                                 socket.SOCK_STREAM,
                                 socket.IPPROTO_TCP)
#            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.bind( ("127.0.0.1", default_port) )
        except socket.error as _msg:  # analysis:ignore
            default_port += 1
        else:
            break
        finally:
            sock.close()
            sock = None
    return default_port
43403
def url(self, var, default=NOTSET, force=True):
        """"""
        return self._get(var, default=default, cast=urlparse.urlparse,
                         force=force)