def traverse_dict(obj, query):
    """
        Get elements inside a nested dict, based on a dict query. The query is defined by a
        string separated by '__'. traverse_dict(foo, 'a__b__c') is roughly equivalent to foo[a][b][c] but
        will short circuit to return None if something on the query is None.
    """
    query = query.split('__')
    for name in query:
        obj = obj.get(name, None)
        if obj is None:
            return None
    return obj
