Exemple #1
0
 def get_attr_key(obj, attr_key):
     # parse "attr[key1][key2][...]"
     attr = attr_key.split('[', 1)[0]
     keys = re.findall(r'\[(.*?)\]', attr_key)
     if attr:
         obj = getattr(obj, attr)
     return get_nested_key(obj, keys)
Exemple #2
0
    def conf_to_init_kwargs(cls, conf):
        """
        Turn a configuration object into a dictionary suitable for passing to
        ``__init__`` as ``**kwargs``.
        """
        kwargs = {}
        for param, conf_path in cls.INIT_KWARGS_KEY_MAP.items():
            try:
                val = get_nested_key(conf, conf_path)
            except KeyError:
                continue
            kwargs[param] = val

        return kwargs
Exemple #3
0
 def _get_base_key_src(conf, path):
     conf = get_nested_key(conf,
                           path[:-1],
                           getitem=conf.__class__._quiet_get_key)
     return conf.resolve_src(path[-1])
Exemple #4
0
 def _get_base_key_val(conf, path):
     return get_nested_key(conf,
                           path,
                           getitem=conf.__class__._quiet_get_key)
Exemple #5
0
 def _get_param_key_desc_map(cls):
     return {
         param: get_nested_key(cls.CONF_CLASS.STRUCTURE, conf_path)
         for param, conf_path in cls.INIT_KWARGS_KEY_MAP.items()
     }