<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def url_to_attrs_dict(url, url_attr):
 """ Sanitize url dict as used in django-bootstrap3 settings. """

    result = dict()
    # If url is not a string, it should be a dict
    if isinstance(url, six.string_types):
        url_value = url
    else:
        try:
            url_value = url["url"]
        except TypeError:
            raise BootstrapError(
                'Function "url_to_attrs_dict" expects a string or a dict with key "url".'
            )
        crossorigin = url.get("crossorigin", None)
        integrity = url.get("integrity", None)
        if crossorigin:
            result["crossorigin"] = crossorigin
        if integrity:
            result["integrity"] = integrity
    result[url_attr] = url_value
    return result