Split and create the port entry for an Ethernet Switch

        :param port_num: port number
        :type port_num: str or int
        :param str port_def: port definition
966506
def calc_ethsw_port(self, port_num, port_def):
        
        # Port String - access 1 SW2 1
        # 0: type 1: vlan 2: destination device 3: destination port
        port_def = port_def.split(' ')
        if len(port_def) == 4:
            destination = {'device': port_def[2],
                           'port': port_def[3]}
        else:
            destination = {'device': 'NIO',
                           'port': port_def[2]}
        # port entry
        port = {'id': self.port_id,
                'name': str(port_num),
                'port_number': int(port_num),
                'type': port_def[0],
                'vlan': int(port_def[1])}
        self.node['ports'].append(port)
        self.calc_link(self.node['id'], self.port_id, port['name'],
                       destination)
        self.port_id += 1
1294677
def delete_port(self, port):
        '''
        
        '''
        port_id = self._find_port_id(port)
        ret = self.network_conn.delete_port(port=port_id)
        return ret if ret else True
513677
def allow_port(port, proto='tcp', direction='both'):
    '''
    
    '''

    ports = get_ports(proto=proto, direction=direction)
    direction = direction.upper()
    _validate_direction_and_proto(direction, proto)
    directions = build_directions(direction)
    results = []
    for direction in directions:
        _ports = ports[direction]
        _ports.append(port)
        results += allow_ports(_ports, proto=proto, direction=direction)
    return results
1053899
def set_lan_port(self, port_id, mac=None):
        
        port_handler = _parse_physical_port_id(port_id)
        port = self._find_port(port_handler)
        if port:
            port_handler.set_lan_port(port, mac)
        else:
            self._add_port(port_handler, port_handler.create_lan_port(mac))
666659
def is_numeric_port (portstr):
    
    if portstr.isdigit():
        port = int(portstr)
        # 65536 == 2**16
        if 0 < port < 65536:
            return port
    return False
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)
676917
def generate_local_port():
    """"""
    global _PREVIOUS_LOCAL_PORT
    if _PREVIOUS_LOCAL_PORT is None:
        try:
            with contextlib.closing(socket.socket(getattr(socket, 'AF_NETLINK', -1), socket.SOCK_RAW)) as s:
                s.bind((0, 0))
                _PREVIOUS_LOCAL_PORT = int(s.getsockname()[0])
        except OSError:
            _PREVIOUS_LOCAL_PORT = 4294967295  # UINT32_MAX
    return int(_PREVIOUS_LOCAL_PORT)
1344737
def port(self, value):
        

        if value is not None:
            assert type(value) is int, "'{0}' attribute: '{1}' type is not 'int'!".format(
                "port", value)
            assert type(value) >= 0 and type(value) >= 65535, \
                "'{0}' attribute: '{1}' value must be in 0-65535 range!".format("port", value)
        self.__port = value
1141801
def p_portlist_io(self, p):
        ''
        p[0] = Portlist(ports=p[2], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
194582
def add_new_data_port(self):
        """"""
        try:
            new_data_port_ids = gui_helper_state_machine.add_data_port_to_selected_states('OUTPUT', int, [self.model])
            if new_data_port_ids:
                self.select_entry(new_data_port_ids[self.model.state])
        except ValueError:
            pass
426448
def add_port_to_free_pool(self, port):
        """"""
        if port < 1 or port > 65535:
            raise ValueError(
                'Port must be in the [1, 65535] range, not %d.' % port)
        port_info = _PortInfo(port=port)
        self._port_queue.append(port_info)
1243479
def p_portlist(self, p):
        ''
        p[0] = Portlist(ports=p[2], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
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))
257889
def splitport(host):
    """"""
    global _portprog
    if _portprog is None:
        import re
        _portprog = re.compile('^(.*):([0-9]+)$')

    match = _portprog.match(host)
    if match: return match.group(1, 2)
    return host, None
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
1092064
def set_tcp_port(self, tcp_port):
        
        if tcp_port is None:
            self.tcp_port = None
            return
        self.tcp_port = int(tcp_port)
309676
def create_switch(type, settings, pin):
	

	switch = None
	if type == "A":
		group, device = settings.split(",")
		switch = pi_switch.RCSwitchA(group, device)

	elif type == "B":
		addr, channel = settings.split(",")
		addr = int(addr)
		channel = int(channel)
		switch = pi_switch.RCSwitchB(addr, channel)

	elif type == "C":
		family, group, device = settings.split(",")
		group = int(group)
		device = int(device)
		switch = pi_switch.RCSwitchC(family, group, device)

	elif type == "D":
		group, device = settings.split(",")
		device = int(device)
		switch = pi_switch.RCSwitchD(group, device)

	else:
		print "Type %s is not supported!" % type
		sys.exit()

	switch.enableTransmit(pin)
	return switch