def get_dict_value(dict_var, key, default_value=None, add_if_not_in_map=True):
    """
    This is like dict.get function except it checks that the dict_var is a dict
    in addition to dict.get.
    @param dict_var: the variable that is either a dict or something else
    @param key: key to look up in dict
    @param default_value: return value if dict_var is not of type dict or key is not in dict_var
    @return:
      either default_value or dict_var[key]
    """

    if (isinstance(dict_var, dict) and key in dict_var):
        result = dict_var[key]
    else:
        result = default_value
        if add_if_not_in_map:
            dict_var[key] = result
    return result