(self, content, keys, traversed_path=None)
return results
Allow to retrieve content nested inside a several layers deep dict/list

        Examples: -content: {
                            "key1": {
                                "key2" : [
                                            {
                                                "name"  : "object1",
                                                "value" : 42
                                            },
                                            {
                                                "name"  : "object2",
                                                "value" : 72
                                            }
                                          ]
                            }
                        }
                  -keys: ["key1", "key2", "1", "value"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72)]
                  -keys: ["key1", "key2", "1", "*"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72), (["key1", "key2", "1", "name"], "object2")]
                  -keys: ["key1", "key2", "*", "value"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72), (["key1", "key2", "0", "value"], 42)]
Allow to retrieve content nested inside a several layers deep dict/list
Allow to retrieve content nested inside a several layers deep dict / list
def deep_get(self, content, keys, traversed_path=None):
        """
        Allow to retrieve content nested inside a several layers deep dict/list

        Examples: -content: {
                            "key1": {
                                "key2" : [
                                            {
                                                "name"  : "object1",
                                                "value" : 42
                                            },
                                            {
                                                "name"  : "object2",
                                                "value" : 72
                                            }
                                          ]
                            }
                        }
                  -keys: ["key1", "key2", "1", "value"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72)]
                  -keys: ["key1", "key2", "1", "*"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72), (["key1", "key2", "1", "name"], "object2")]
                  -keys: ["key1", "key2", "*", "value"]
                    would return:
                        [(["key1", "key2", "1", "value"], 72), (["key1", "key2", "0", "value"], 42)]
        """

        if traversed_path is None:
            traversed_path = []

        if keys == []:
            return [(traversed_path, content)]

        key = keys[0]
        if key.isalnum():
            # key is not a regex, simply match for equality
            matcher = key.__eq__
        else:
            # key might be a regex
            key_regex = self._regexes.get(key)
            if key_regex is None:
                # we don't have it cached, compile it
                regex = "^{}$".format(key)
                try:
                    key_regex = re.compile(regex)
                except Exception:
                    self.warning("Cannot compile regex: %s", regex)
                    return []
                self._regexes[key] = key_regex
            matcher = key_regex.match

        results = []
        for new_key, new_content in self.items(content):
            if matcher(new_key):
                results.extend(self.deep_get(new_content, keys[1:], traversed_path + [str(new_key)]))
        return results
def deep_get ( self , content , keys , traversed_path = None ) : if traversed_path is None : traversed_path = [ ] if keys == [ ] : return [ ( traversed_path , content ) ] key = keys [ 0 ] if key . isalnum ( ) : # key is not a regex, simply match for equality matcher = key . __eq__ else : # key might be a regex key_regex = self . _regexes . get ( key ) if key_regex is None : # we don't have it cached, compile it regex = "^{}$" . format ( key ) try : key_regex = re . compile ( regex ) except Exception : self . warning ( "Cannot compile regex: %s" , regex ) return [ ] self . _regexes [ key ] = key_regex matcher = key_regex . match results = [ ] for new_key , new_content in self . items ( content ) : if matcher ( new_key ) : results . extend ( self . deep_get ( new_content , keys [ 1 : ] , traversed_path + [ str ( new_key ) ] ) ) return results