def safe_get(dictionary, key, default_value, can_return_none=True):
    """
    Safely perform a dictionary get,
    returning the default value if the key is not found.

    :param dict dictionary: the dictionary
    :param string key: the key
    :param variant default_value: the default value to be returned
    :param bool can_return_none: if ``True``, the function can return ``None``;
                                 otherwise, return ``default_value`` even if the
                                 dictionary lookup succeeded
    :rtype: variant
    """
    return_value = default_value
    try:
        return_value = dictionary[key]
        if (return_value is None) and (not can_return_none):
            return_value = default_value
    except (KeyError, TypeError):
        # KeyError if key is not present in dictionary
        # TypeError if dictionary is None
        pass
    return return_value