def load(self, spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None) -> "DLDict": if load_args: _kwargs = {"load_args": load_args} _load_args = {} else: _load_args = {} _kwargs = {} if init_args: _kwargs["init_args"] = init_args for attr, (_item_cls, _item) in spec.items(): _cls = importer(_item_cls) if issubclass(_cls, ImpExp) and init_args: _args = { k: v for k, v in init_args.items() if k in _cls.init_args } else: _args = {} _x = _cls(**_args) _x.load(_item, **_kwargs) self.db[attr] = _x self.local_load_adjustments(**_load_args) return self
def load_class_map(spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None) -> dict: _item = {} for key, val in spec.items(): _item[key] = importer(val) return _item
def __init__(self, base_class=Message): if isinstance(base_class, str): self.base_class = importer(base_class)() elif isinstance(base_class, Message): self.base_class = base_class elif type(base_class) == abc.ABCMeta: self.base_class = base_class() self.info = {}
def load_dldict(spec: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None) -> dict: db = {} for attr, (_item_cls, _item) in spec.items(): _class = importer(_item_cls) if issubclass(_class, Message): db[attr] = _class().from_dict(_item) else: if issubclass(_class, ImpExp) and init_args: _args = { k: v for k, v in init_args.items() if k in _class.init_args } else: _args = {} db[attr] = _class(**_args).load(_item) return db