def sanitize_redirect(host, redirect_to):
    """
    Given the hostname and an untrusted URL to redirect to,
    this method tests it to make sure it isn't garbage/harmful
    and returns it, else returns None, similar as how's it done
    on django.contrib.auth.views.
    """
    if redirect_to:
        try:
            # Don't redirect to a different host
            netloc = urlparse(redirect_to)[1] or host
        except (TypeError, __HOLE__):
            pass
        else:
            if netloc == host:
                return redirect_to
dataset/ETHPy150Open omab/python-social-auth/social/utils.py/sanitize_redirect