(self, key, default=None, list_ok=False)
multi-level get that expects dicts within dicts
multi-level get that expects dicts within dicts
multi - level get that expects dicts within dicts
def mlget(self, key, default=None, list_ok=False):
        # type: (Any, Any, Any) -> Any
        """multi-level get that expects dicts within dicts"""
        if not isinstance(key, list):
            return self.get(key, default)
        # assume that the key is a list of recursively accessible dicts

        def get_one_level(key_list, level, d):
            # type: (Any, Any, Any) -> Any
            if not list_ok:
                assert isinstance(d, dict)
            if level >= len(key_list):
                if level > len(key_list):
                    raise IndexError
                return d[key_list[level - 1]]
            return get_one_level(key_list, level + 1, d[key_list[level - 1]])

        try:
            return get_one_level(key, 1, self)
        except KeyError:
            return default
        except (TypeError, IndexError):
            if not list_ok:
                raise
            return default
def mlget ( self , key , default = None , list_ok = False ) : # type: (Any, Any, Any) -> Any if not isinstance ( key , list ) : return self . get ( key , default ) # assume that the key is a list of recursively accessible dicts def get_one_level ( key_list , level , d ) : # type: (Any, Any, Any) -> Any if not list_ok : assert isinstance ( d , dict ) if level >= len ( key_list ) : if level > len ( key_list ) : raise IndexError return d [ key_list [ level - 1 ] ] return get_one_level ( key_list , level + 1 , d [ key_list [ level - 1 ] ] ) try : return get_one_level ( key , 1 , self ) except KeyError : return default except ( TypeError , IndexError ) : if not list_ok : raise return default