Reserves and returns a list of `num_ports` contiguous unused ports.
557645
def pick_contiguous_unused_ports(
    num_ports,
    retry_interval_secs=3,
    retry_attempts=5):
  """"""
  for _ in range(retry_attempts):
    start_port = portpicker.pick_unused_port()
    if start_port is not None:
      ports = [start_port + p for p in range(num_ports)]
      if all(portpicker.is_port_free(p) for p in ports):
        return ports
      else:
        return_ports(ports)

    time.sleep(retry_interval_secs)

  raise RuntimeError("Unable to obtain %d contiguous unused ports." % num_ports)
1248769
def unused_keys(self):
        """"""
        unused = set()
        for k, c in self._children.items():
            if isinstance(c, ConfigNode):
                if not c.has_been_accessed():
                    unused.add(k)
            else:
                for ck in c.unused_keys():
                    unused.add(k+'.'+ck)
        return unused
984037
def calc_mb_ports(self):
        
        model = self.device_info['model']
        chassis = self.device_info['chassis']
        num_ports = MODEL_MATRIX[model][chassis]['ports']
        ports = []

        if num_ports > 0:
            port_type = MODEL_MATRIX[model][chassis]['type']

            # Create the ports dict
            for i in range(num_ports):
                port_temp = {'name': PORT_TYPES[port_type] + '0/' + str(i),
                             'id': self.port_id,
                             'port_number': i,
                             'slot_number': 0}
                ports.append(port_temp)
                self.port_id += 1
        self.node['ports'].extend(ports)
594115
public static ImmutableSortedSet<String> hosts(int...ports) {
        if (ports.length == 0) {
            return ImmutableSortedSet.of(
                    HostAndPort.fromParts("", Constants.DEFAULT_INTERNAL_PORT).toString());
        }
        ImmutableSortedSet.Builder<String> sbld = ImmutableSortedSet.naturalOrder();
        for (int p: ports) {
            sbld.add(HostAndPort.fromParts("", p).toString());
        }
        return sbld.build();
    }
540870
def export_capacities(self):
        
        return [export for cls in getmro(type(self)) if hasattr(cls, "EXPORT_TO") for export in cls.EXPORT_TO]
23951
def port_ranges():
    
    try:
        return _linux_ranges()
    except (OSError, IOError): # not linux, try BSD
        try:
            ranges = _bsd_ranges()
            if ranges:
                return ranges
        except (OSError, IOError):
            pass

    # fallback
    return [DEFAULT_EPHEMERAL_PORT_RANGE]
1025425
def _unassigned_ports():
    
    free_ports = ranges_to_set(_parse_ranges(_iana_unassigned_port_ranges()))
    known_ports = ranges_to_set(_wikipedia_known_port_ranges())
    return free_ports.difference(known_ports)
785906
def available_ports(self):
        
        from mbuild.port import Port
        return [port for port in self.labels.values()
                if isinstance(port, Port) and not port.used]
1015776
def _port_ranges_to_set(ranges):
        
        return set([i for r in ranges for i in range(r.start, r.end + 1)])
790547
def get_cap_files(self, *ports):
        
        cap_files = {}
        for port in ports:
            if port.cap_file_name:
                with open(port.cap_file_name) as f:
                    cap_files[port] = f.read().splitlines()
            else:
                cap_files[port] = None
        return cap_files
673290
function getAvailablePortSeries(start, quantity, increment = 1) {
  const startPort = start;
  const endPort = start + (quantity - 1);

  return findAPortInUse(startPort, endPort, '127.0.0.1').then((port) => {
    if (typeof port === 'number') {
      return getAvailablePortSeries(port + increment, quantity);
    }

    const ports = [];

    for (let i = startPort; i <= endPort; i += increment) {
      ports.push(i);
    }

    return ports;
  });
}
248418
def parse_ports(ports_text):
    
    ports_set = set()
    for bit in ports_text.split(','):
        if '-' in bit:
            low, high = bit.split('-', 1)
            ports_set = ports_set.union(range(int(low), int(high) + 1))
        else:
            ports_set.add(int(bit))
    return sorted(list(ports_set))
946138
def dest_ports(self):
        
        start_port = self.blacklist.get('BlacklistEntryDestinationPort')
        if start_port is not None:
            return '{}-{}'.format(
                start_port, self.blacklist.get('BlacklistEntryDestinationPortRange'))
        return 'ANY'
345085
def find_bound_ports(self, ports):
        """"""
        bound = []
        for port in ports:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.bind((port.ip if port.ip is not NotSpecified else "127.0.0.1", port.host_port))
            except socket.error as error:
                bound.append(port.host_port)
            finally:
                s.close()

        if bound:
            raise AlreadyBoundPorts(ports=bound)
762395
def _extract_ports(port_string):
    
    _ports = str(port_string)
    if '-' in _ports:
        start, end = _ports.split('-')
        return {'min_port': start, 'max_port': end}
    return {'min_port': _ports, 'max_port': _ports}
288221
protected function get_whitelisted_ports() {
        global $CFG;
        if (!isset($CFG->curlsecurityallowedport)) {
            return [];
        }
        return array_filter(array_map('trim', explode("\n", $CFG->curlsecurityallowedport)), function($entry) {
            return !empty($entry);
        });
    }
1015378
def _next_port(self, port):
        
        port = 5000 + (port + 1) % 1000
        if port == self.port:
            raise DatacatsError('Too many instances running')
        return port