async def refresh(log=True): # pragma: no cover: used in production only async with utils.wait_for_redis(): services = parse_torrc(settings.TORRC_FILE, log=log) services_dict = { service.name: dataclass_asdict(service) for service in services } anonymous_services_dict = { service.name: { "name": service.name, "hostname": service.hostname } for service in services } onion_host = services_dict.get("BitcartCC Merchants API", "") if onion_host: onion_host = onion_host["hostname"] or "" await settings.redis_pool.hmset_dict( REDIS_KEY, { "onion_host": onion_host, "services_dict": json.dumps(services_dict), "anonymous_services_dict": json.dumps(anonymous_services_dict), }, )
def default(self, o): """ Render dataclass content as dict """ if is_dataclass(o): return dataclass_asdict(o) return super().default(o)
def asdict(self, recursive=True, private=False, protected=True, public=True): d = {} for k, v in self.__namespace.items(): if k[0] == '_': if '__' in k: if not private: continue elif not protected: continue if k[0] != '_' and not public: continue if recursive: if isinstance(v, Namespace): v = v.asdict(recursive=recursive, private=private, protected=protected, public=public) if not private and is_dataclass(v) and not isinstance(v, type): v = dataclass_asdict(v) d[k] = v return d
def convert_args_to_matter_config(args: argparse.Namespace) -> MatterTestConfig: config = MatterTestConfig() # Populate commissioning config if present, exiting on error if not populate_commissioning_args(args, config): sys.exit(1) config.storage_path = pathlib.Path(_DEFAULT_STORAGE_PATH) if args.storage_path is None else args.storage_path config.logs_path = pathlib.Path(_DEFAULT_LOG_PATH) if args.logs_path is None else args.logs_path config.paa_trust_store_path = args.paa_trust_store_path config.ble_interface_id = args.ble_interface_id config.controller_node_id = args.controller_node_id # Accumulate all command-line-passed named args all_global_args = [] argsets = [item for item in (args.int_arg, args.float_arg, args.string_arg, args.json_arg, args.hex_arg, args.bool_arg) if item is not None] for argset in argsets: all_global_args.extend(argset) config.global_test_params = {} for name, value in all_global_args: config.global_test_params[name] = value # Embed the rest of the config in the global test params dict which will be passed to Mobly tests config.global_test_params["meta_config"] = {k: v for k, v in dataclass_asdict(config).items() if k != "global_test_params"} return config
def _create_twine_settings(self, addon_kwargs: Dict[str, Any]) -> TwineSettings: """ Gather all parameters that had a value set during instantiation and pass them to Twine which then validates and laods the config. """ params = { name: val for name, val in dataclass_asdict(self).items() if val } settings = TwineSettings(**params, **addon_kwargs) return settings
def aslist(self, recursive=True, private=False, protected=True, public=True): if not recursive: return list(self._list) l = [] for v in self._list: if isinstance(v, Namespace): v = v.asdict(recursive=recursive, private=private, protected=protected, public=public) if not private and is_dataclass(v) and not isinstance(v, type): v = dataclass_asdict(v) l.append(v) return l
def refresh(): TorService.services = parse_torrc(settings.TORRC_FILE) TorService.services_dict = { service.name: dataclass_asdict(service) for service in TorService.services } TorService.anonymous_services_dict = { service.name: { "name": service.name, "hostname": service.hostname } for service in TorService.services } TorService.onion_host = TorService.services_dict.get( "BitcartCC Merchants API", "") if TorService.onion_host: # pragma: no cover TorService.onion_host = TorService.onion_host["hostname"]
async def get_queue( self, routing_key: str, queue_options: Optional[QueueOptions] = None) -> aio_pika.Queue: """ Set up worker queue or get previously declared one using this connection. :param routing_key: of queue. :param queue_options: Options for pika queue creation. :return: Requested queue. """ try: return self._queues[routing_key] except KeyError: pass if queue_options is None: queue_options = QueueOptions() queue_kwargs = dataclass_asdict(queue_options) logger = logging.root while True: try: queue = await self.channel.declare_queue( routing_key, **queue_kwargs) except AttributeError: if self.connection is None: raise RuntimeError("Connection is not established") else: await self.get_channel() else: logger.info(f"RABBITMQ `{routing_key}` QUEUE DECLARED") break self._queues[routing_key] = queue return queue
def get_as_dict(self) -> Mapping[str, Any]: """ Returns a mapping from the dataclass field name to the value. """ return dataclass_asdict(self)