Check whether gate is spawnable on the target channels.
424682
def _check_spawnable(source_channels, target_channels):
    """"""
    if len(target_channels) != len(set(target_channels)):
        raise Exception('Spawn channels must be unique')
    return source_channels.issubset(
        set(target_channels))
149477
def on_channel_flow(self, method):
        
        if method.active:
            LOGGER.info('Channel flow is active (READY)')
            self.state = self.STATE_READY
            if self.on_ready:
                self.on_ready(self)
        else:
            LOGGER.warning('Channel flow is inactive (BLOCKED)')
            self.state = self.STATE_BLOCKED
            if self.on_unavailable:
                self.on_unavailable(self)
404236
def _gencode_gate_class(self):
        
        channels, verts = self.coordinates
        num_channels = len(channels)
        gate_type_name = self.gate_type.__name__
        if gate_type_name == 'ThresholdGate' and num_channels == 2:
            gate_type_name = 'QuadGate'
        return gate_type_name
360364
def daemons_reachability_check(self):
        
        # First look if it's not too early to ping
        start = time.time()
        if self.daemons_last_reachable_check and \
                self.daemons_last_reachable_check + self.conf.daemons_check_period > start:
            logger.debug("Too early to check daemons reachability, check period is %.2f seconds",
                         self.conf.daemons_check_period)
            return True

        _t0 = time.time()
        logger.debug("Alignak daemons reachability check")
        result = self.dispatcher.check_reachable()
        statsmgr.timer('dispatcher.check-alive', time.time() - _t0)

        _t0 = time.time()
        logger.debug("Alignak daemons status get")
        events = self.dispatcher.check_status_and_get_events()
        duration = time.time() - _t0
        statsmgr.timer('dispatcher.check-status', duration)
        logger.debug("Getting daemons status duration: %.2f seconds", duration)

        # Send the collected events to the Alignak logger
        for event in events:
            event.prepare()
            make_monitoring_log(event.data['level'], event.data['message'],
                                timestamp=event.creation_time, to_logger=True)

            # Add to the recent events for the WS endpoint
            event.data['timestamp'] = event.creation_time
            event.data['date'] = datetime.fromtimestamp(event.creation_time).\
                strftime(self.conf.events_date_format)
            event.data.pop('instance_id')
            self.recent_events.append(event.data)

        # Set the last check as now
        self.daemons_last_reachable_check = start

        logger.debug("Checking daemons reachability duration: %.2f seconds", time.time() - start)

        return result
596195
private static boolean isAvailable(int thePort) {
		ourLog.info("Testing a bind on thePort {}", thePort);
		try (ServerSocket ss = new ServerSocket()) {
			ss.setReuseAddress(true);
			ss.bind(new InetSocketAddress("0.0.0.0", thePort));
			try (DatagramSocket ds = new DatagramSocket()) {
				ds.setReuseAddress(true);
				ds.connect(new InetSocketAddress("127.0.0.1", thePort));
				ourLog.info("Successfully bound thePort {}", thePort);
			} catch (IOException e) {
				ourLog.info("Failed to bind thePort {}: {}", thePort, e.toString());
				return false;
			}
		} catch (IOException e) {
			ourLog.info("Failed to bind thePort {}: {}", thePort, e.toString());
			return false;
		}

		try (ServerSocket ss = new ServerSocket()) {
			ss.setReuseAddress(true);
			ss.bind(new InetSocketAddress("localhost", thePort));
		} catch (IOException e) {
			ourLog.info("Failed to bind thePort {}: {}", thePort, e.toString());
			return false;
		}

		return true;
	}
812285
def validate_target(self, target):
        """"""

        archs = target.split('/')

        for arch in archs:
            if not arch in self.archs:
                return False

        return True
1253497
private boolean isAvailable(
                                BaseDestinationHandler destinationHandler,
                                DestinationAvailability destinationAvailability)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "isAvailable", new Object[] { destinationHandler, destinationAvailability });

        boolean sendAvailable = false;
        boolean receiveAvailable = false;

        if (destinationAvailability == DestinationAvailability.SEND
            || destinationAvailability == DestinationAvailability.SEND_AND_RECEIVE)
        {
            // Destination must be a non-mediated destination with a local queue point
            if (destinationHandler.hasLocal())
            {
                sendAvailable = true;
            }

            if (sendAvailable)
            {
                if ((destinationHandler.definition.isSendAllowed())
                    && (isLocalizationAvailable(destinationHandler, destinationAvailability)))
                {
                    sendAvailable = true;
                }
                else
                {
                    sendAvailable = false;
                }
            }
        }

        if (destinationAvailability == DestinationAvailability.RECEIVE
            || destinationAvailability == DestinationAvailability.SEND_AND_RECEIVE)
        {
            // Destination must have a queue point on the ME to which the connection is connected
            if (destinationHandler.hasLocal())
            {
                receiveAvailable = true;
            }

            if (receiveAvailable)
            {
                if ((destinationHandler.definition.isReceiveAllowed())
                    && (isLocalizationAvailable(destinationHandler, destinationAvailability)))
                {
                    receiveAvailable = true;
                }
                else
                {
                    receiveAvailable = false;
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "isAvailable", new Object[] { new Boolean(sendAvailable || receiveAvailable) });

        return (sendAvailable || receiveAvailable);
    }
1336962
def check_hook_mechanism_is_intact(module):
    
    result = True
    if check_register_present(module):
        result = not result
    if check_deregister_present(module):
        result = not result
    return result
1207132
def lock_exists_in_either_channel_side(
        channel_state: NettingChannelState,
        secrethash: SecretHash,
) -> bool:
    """"""
    lock = get_lock(channel_state.our_state, secrethash)
    if not lock:
        lock = get_lock(channel_state.partner_state, secrethash)
    return lock is not None
462122
def validate_gate():
    """"""
    try:
        credentials = get_env_credential()
        LOG.debug('Found credentials: %s', credentials)
        LOG.info('Gate working.')
    except TypeError:
        LOG.fatal('Gate connection not valid: API_URL = %s', API_URL)
660108
function detectPorting(target) {
    const PORTING_DEV_DIR = path.join(config.dir.src, config.dir.porting);
    const PLATFORMS_ROOT = path.join(__dirname, '..', 'platforms');

    const valid_targets = [];

    // valid porting
    if (!fs.existsSync(PORTING_DEV_DIR)) {
        return valid_targets;
    }

    const temp_targets = [];

    if (null == target || 'all' === target) {
        temp_targets.push('dev');
        fs.readdirSync(PLATFORMS_ROOT)
        .forEach((find) => {
            const findPath = path.join(PLATFORMS_ROOT, find);
            if (fs.statSync(findPath).isDirectory()) {
                temp_targets.push(find);
            }
        });
    } else {
        const _targets = target.split(',');
        _targets.forEach((_tgt) => {
            temp_targets.push(_tgt);
        });
    }

    temp_targets.forEach((candidate) => {
        if ('dev' === candidate) {
            valid_targets.push('dev');
        } else {
            if (fs.existsSync(path.join('platforms', candidate, config.dir.porting))) {
                valid_targets.push(candidate);
            }
        }
    });

    return valid_targets;
}
1064389
def is_native_ion_gate(gate: ops.Gate) -> bool:
    
    return isinstance(gate, (ops.XXPowGate,
                             ops.MeasurementGate,
                             ops.XPowGate,
                             ops.YPowGate,
                             ops.ZPowGate))
253970
def is_available(self) -> bool:
        """"""
        status_response = self.get_state(
            'api/host/daemonCheck.json'
        )

        if not status_response:
            return False

        return status_response.get('result') == 1
166239
def set_axes(self, channels, ax):
        
        # To make sure displayed as hist
        if len(set(channels)) == 1:
            channels = channels[0],

        self.current_channels = channels
        # Remove existing gates
        for gate in self.gates:
            gate.remove_spawned_gates()
        ## 
        # Has a clear axis command inside!!
        # which will "force kill" spawned gates
        self.plot_data()

        for gate in self.gates:
            sgate = gate.spawn(channels, ax)
            gate._refresh_activation()
463787
def opened(self, block_identifier: BlockSpecification) -> bool:
        
        return self.token_network.channel_is_opened(
            participant1=self.participant1,
            participant2=self.participant2,
            block_identifier=block_identifier,
            channel_identifier=self.channel_identifier,
        )
1291489
def enabled?(thing = nil)
      instrument(:enabled?) do |payload|
        values = gate_values
        thing = gate(:actor).wrap(thing) unless thing.nil?
        payload[:thing] = thing
        context = FeatureCheckContext.new(
          feature_name: @name,
          values: values,
          thing: thing
        )

        if open_gate = gates.detect { |gate| gate.open?(context) }
          payload[:gate_name] = open_gate.name
          true
        else
          false
        end
      end
    end
1339079
def check_link_and_get_info(self, target_id=0xFF):
        """"""
        for _ in range(0, 5):
            if self._update_info(target_id):
                if self._in_boot_cb:
                    self._in_boot_cb.call(True, self.targets[
                        target_id].protocol_version)
                if self._info_cb:
                    self._info_cb.call(self.targets[target_id])
                return True
        return False