Return a port number from 5000-5999 based on the environment name
        to be used as a default when the user hasn't selected one.
552738
def _choose_port(self):
        
        # instead of random let's base it on the name chosen (and the site name)
        return 5000 + unpack('Q',
                             sha((self.name + self.site_name)
                             .decode('ascii')).digest()[:8])[0] % 1000
457702
def port(self, port=None):
        
        if (port is None) or (port == self.__port):
            return self.__port
        # when port change ensure old socket is close
        self.close()
        # valid port ?
        if 0 < int(port) < 65536:
            self.__port = int(port)
            return self.__port
        else:
            return None
37005
function (ui, done) {
        var port = ui.options.get("port");
        var listenHost = ui.options.get("listen", "localhost");
        ui.bs.utils.portscanner.findAPortNotInUse(port, port + 100, {
            host: listenHost,
            timeout: 1000
        }, function (err, port) {
            if (err) {
                return done(err);
            }
            done(null, {
                options: {
                    port: port
                }
            });
        });
    }
1297834
def port(self):
        
        try:
            rv = int(to_native(self._split_host()[1]))
            if 0 <= rv <= 65535:
                return rv
        except (ValueError, TypeError):
            pass
1119923
def getConf(cls, settings, options):
        ""
        ports = ['http_port', 'https_port', 'cache_port']
        for port_name in ports:
            port = getattr(settings, port_name.upper(), None)
            # only use the settings ports if the defaults were left unchanged
            default = getattr(defaults, port_name.upper())
            if port and options.get(port_name) == default:
                options[port_name] = port

        _opts = [
            ('key', 'hx_private_key'),
            ('cert', 'hx_certficate'),
            ('wsgi', 'wsgi_application')
        ]
        for opt_name, settings_name in _opts:
            opt = getattr(settings, settings_name.upper(), None)
            if opt:
                options[opt_name] = opt

        if not options['settings']:
            options['settings'] = environ['DJANGO_SETTINGS_MODULE']
        return options
28494
def _find_port(self, host):  # pylint: disable=no-self-use
        
        ind = host.rfind(":")
        if ind != -1:
            try:
                port = int(host[ind + 1:])
                host = host[:ind]
            except ValueError:
                port = 3000
        else:
            port = 3000
        return host, port
163574
private int getPort() {
		String port = getGangliaConfig(args.getPort(), ganglia, "port",
				DEFAULT_PORT);
		return Integer.parseInt(port);
	}
968845
public static int getFreePort(int defaultPort) throws IOException {
    try (
        ServerSocket serverSocket = new ServerSocket(defaultPort)
    ) {
      return serverSocket.getLocalPort();
    } catch (IOException e) {
      return getFreePort();
    }
  }
391892
def get_free_tcp_port(self, project, port_range_start=None, port_range_end=None):
        

        # use the default range is not specific one is given
        if port_range_start is None and port_range_end is None:
            port_range_start = self._console_port_range[0]
            port_range_end = self._console_port_range[1]

        port = self.find_unused_port(port_range_start,
                                     port_range_end,
                                     host=self._console_host,
                                     socket_type="TCP",
                                     ignore_ports=self._used_tcp_ports)

        self._used_tcp_ports.add(port)
        project.record_tcp_port(port)
        log.debug("TCP port {} has been allocated".format(port))
        return port
1230577
def get_host_port(spec, default_port):
    ""
    args = (spec.split(':', 1) + [default_port])[:2]
    args[1] = int(args[1])
    return args[0], args[1]
426058
function resolveHostAndPort() {
  return this._options ? [this._options.host || defaultHost, this._options.port || defaultPort] :
    [defaultHost, defaultPort];
}
762558
async function findWindowsPortRange() {
  // First, check if we're running on XP.  If this initial command fails,
  // we just fallback on the default IANA range.
  let stdout = await execute('cmd.exe /c ver');
  if (/Windows XP/.test(stdout)) {
    // TODO: Try to read these values from the registry.
    return {min: 1025, max: 5000};
  } else {
    stdout = await execute('netsh int ipv4 show dynamicport tcp');
    /* > netsh int ipv4 show dynamicport tcp
      Protocol tcp Dynamic Port Range
      ---------------------------------
      Start Port : 49152
      Number of Ports : 16384
     */
    let range = stdout.split(/\n/)
        .filter((line) => /.*:\s*\d+/.test(line))
        .map((line) => Number(line.split(/:\s*/)[1]));
    return {
      min: range[0],
      max: range[0] + range[1]
    };
  }
}
718159
public static int getDefaultPort( String protocol ) {
    if( HTTP_PROTOCOL.equals(protocol) ) { return DEFAULT_HTTP_PORT; }
    else if( HTTPS_PROTOCOL.equals(protocol) ) { return DEFAULT_HTTPS_PORT; }
    else { throw new IllegalArgumentException("No known default for "+protocol); }
  }
1107826
def get_host(self, use_x_forwarded=True):
        """"""
        # We try three options, in order of decreasing preference.
        if use_x_forwarded and ('HTTP_X_FORWARDED_HOST' in self.environ):
            host = self.environ['HTTP_X_FORWARDED_HOST']
            port = self.environ.get('HTTP_X_FORWARDED_PORT')
            if port and port != ('443' if self.is_secure else '80'):
                host = '%s:%s' % (host, port)
            return host
        elif 'HTTP_HOST' in self.environ:
            host = self.environ['HTTP_HOST']
        else:
            # Reconstruct the host using the algorithm from PEP 333.
            host = self.environ['SERVER_NAME']
            server_port = str(self.environ['SERVER_PORT'])
            if server_port != ('443' if self.is_secure else '80'):
                host = '%s:%s' % (host, server_port)
        return host
348868
def port(self, name):
        
        for p in self.ports:
            if p.name == name:
                return p
517670
def get_open_port(host="localhost"):
    
    temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    temp_sock.bind((host, 0))
    port = temp_sock.getsockname()[1]
    temp_sock.close()
    del temp_sock
    return port
278235
def select_ip_version(host, port):
    """"""
    # disabled due to problems with current ipv6 implementations
    # and various operating systems.  Probably this code also is
    # not supposed to work, but I can't come up with any other
    # ways to implement this.
    ##try:
    ##    info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
    ##                              socket.SOCK_STREAM, 0,
    ##                              socket.AI_PASSIVE)
    ##    if info:
    ##        return info[0][0]
    ##except socket.gaierror:
    ##    pass
    if ':' in host and hasattr(socket, 'AF_INET6'):
        return socket.AF_INET6
    return socket.AF_INET