def check_db_fixed_input_config() -> State: fixed_input_configuration = fi_configuration() product_tags = products.get_tags() fixed_inputs = FixedInputTable.query.options(joinedload(FixedInputTable.product)).all() data: Dict = {"fixed_inputs": [], "by_tag": {}} errors: List = [] for tag in product_tags: data["by_tag"][tag] = [] for fi in fixed_inputs: fi_data: Dict = first_true( fixed_input_configuration["fixed_inputs"], {}, lambda i: i["name"] == fi.name # noqa: B023 ) if not fi_data: errors.append(fi) if fi.value not in fi_data["values"]: errors.append(fi) tag_data = {one(fi) for fi in fixed_input_configuration["by_tag"][fi.product.tag]} tag_data_required = {one(fi) for fi in fixed_input_configuration["by_tag"][fi.product.tag] if fi[one(fi)]} if not tag_data: errors.append(fi) if {fi.name for fi in fi.product.fixed_inputs} - set(tag_data): errors.append(fi.product.name) if set(tag_data_required) - {fi.name for fi in fi.product.fixed_inputs}: errors.append(fi.product.name) if errors: raise ProcessFailure("Errors in fixed input config", errors) return {"check_db_fixed_input_config": True}
async def get_addr(self, host: str, port: int) -> Optional[Tuple[str, int]]: sock_type_getter = itemgetter(1) dst_address_getter = itemgetter(4) info = first_true( iterable=await self._loop.getaddrinfo(host=host, port=port), default=None, pred=lambda _: sock_type_getter(_) == self.__sock_type__, ) return info and dst_address_getter(info)
async def inner(address: Address) -> Optional[Address]: try: info_all = await asyncio.get_running_loop().getaddrinfo( *address, family=family, proto=proto, flags=flags, ) except socket.gaierror: logging.error(' %s: Name or service not known', address.host) raise info = first_true( iterable=info_all, default=None, pred=lambda _: sock_type_getter(_) == socket_type, ) return info and Address(*dst_address_getter(info))
def protocol_by_name(cls, name: str) -> Optional[Type[BaseProtocol]]: return first_true( BaseProtocol.protocols, default=None, pred=lambda protocol: protocol.name.lower() == name.lower(), )
def first_true( self, default: bool = False, pred: Optional[Callable[[_T], object]] = None, ) -> Union[_T, bool]: return first_true(self._iterable, default=default, pred=pred)
def first_true( self, default: bool = False, pred: Optional[Callable[[_T], bool]] = None, ) -> "ChainedIterable[_T]": return first_true(self._iterable, default=default, pred=pred)