Return port if it is not default port, else None.

    >>> _normalize_port('http', '80')

    >>> _normalize_port('http', '8080')
    '8080'
194338
def _normalize_port(scheme, port):
    
    if not scheme:
        return port
    if port and port != DEFAULT_PORT[scheme]:
        return port
1032094
def port_str(self):
        """"""
        if self.transport is NotSpecified:
            return str(self.port)
        else:
            return "{0}/{1}".format(self.port, self.transport)
1174973
def get_port_stats(port):
    
    cnts = defaultdict(int)
    for c in psutil.net_connections():
        c_port = c.laddr[1]
        if c_port != port:
            continue
        status = c.status.lower()
        cnts[status] += 1
    return cnts
628320
function normalizePort(val, def=3000) {
    var port = parseInt(val, 10);

    // named pipe
    if (isNaN(port)) return val;

    // port number
    if (port >= 0) return port;

    return def;
}
1136507
def port(self, port_range: PortRange = PortRange.ALL) -> int:
        
        if port_range and port_range in PortRange:
            return self.random.randint(*port_range.value)
        else:
            raise NonEnumerableError(PortRange)
963007
def _port_not_in_use():
    """"""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    port = 0
    s.bind(('', port))
    _, port = s.getsockname()
    return port
1066831
def check_port(helper, port):
    
    try:
        int(port)
    except ValueError:
        helper.exit(summary="Port (-p) must be a integer value.", exit_code=unknown, perfdata='')
86841
def p_instance_port_arg_none(self, p):
        ''
        p[0] = PortArg(p[2], None, lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
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
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
855495
def parse_host_port (host_port):
    """"""
    host, port = urllib.splitport(host_port.strip())
    if port is not None:
        if urlutil.is_numeric_port(port):
            port = int(port)
    return host, port
861955
async function resolvePort (port) {
  const portfinder = require('portfinder')
  portfinder.basePort = parseInt(port) || 8080
  port = await portfinder.getPortPromise()
  return port
}
554506
def add_port(self, port):
        
        self.ports.append(port)
        if port.io_type not in self.port_seqs:
            self.port_seqs[port.io_type] = 0
        self.port_seqs[port.io_type] += 1
        port.sequence = self.port_seqs[port.io_type]
        return self
989971
def _get_valid_port(self, port):
        
        if '/' in port:
            port, protocol = port.split('/')
        else:
            protocol = 'tcp'

        try:
            int(port)
        except ValueError:
            raise ValueError("{0} isn't a valid port number.".format(port))

        if protocol not in ('tcp', 'udp'):
            raise ValueError("exposed ports only supports udp or tcp. {0} was passed".format(protocol))

        return "{0}/{1}".format(port, protocol)
787501
def find_available_local_port():
	
	infos = socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM)
	family, proto, _, _, addr = next(iter(infos))
	sock = socket.socket(family, proto)
	sock.bind(addr)
	addr, port = sock.getsockname()[:2]
	sock.close()
	return port
288956
def _normalize_server_url(self, server):
        
        server = server if server.startswith(("http://", "https://")) else "http://{}".format(server)
        return server
476211
def port(self):
        """"""
        self._port = self.lib.iperf_get_test_server_port(self._test)
        return self._port