# Path: social/utils.py
# 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.
#     """
#     # Quick sanity check.
#     if not redirect_to or not isinstance(redirect_to, six.string_types):
#         return None
# 
#     # Heavier security check, don't allow redirection to a different host.
#     netloc = urlparse(redirect_to)[1]
#     if netloc and netloc != host:
#         return None
#     return redirect_to
# 
# def user_is_authenticated(user):
#     if user and hasattr(user, 'is_authenticated'):
#         if isinstance(user.is_authenticated, collections.Callable):
#             authenticated = user.is_authenticated()
#         else:
#             authenticated = user.is_authenticated
#     elif user:
#         authenticated = True
#     else:
#         authenticated = False
#     return authenticated
# 
# def user_is_active(user):
#     if user and hasattr(user, 'is_active'):
#         if isinstance(user.is_active, collections.Callable):
#             is_active = user.is_active()
#         else:
#             is_active = user.is_active
#     elif user:
#         is_active = True
#     else:
#         is_active = False
#     return is_active


from social.p3 import quote
from social.utils import sanitize_redirect, user_is_authenticated, \
                         user_is_active
                      strategy.setting('LOGIN_URL')
    if strategy.session_get('partial_pipeline'):
        idx, backend, xargs, xkwargs = strategy.from_session(
            strategy.session_pop('partial_pipeline')
        )
        if backend == strategy.backend_name:
            kwargs = kwargs.copy()
            kwargs.setdefault('user', user)
            kwargs.update(xkwargs)
            user = strategy.continue_pipeline(pipeline_index=idx,
                                              *xargs, **xkwargs)
        else:
            strategy.clean_partial_pipeline()
            user = strategy.complete(user=user, request=strategy.request,
                                     *args, **kwargs)
    else:
        user = strategy.complete(user=user, request=strategy.request,
                                 *args, **kwargs)

    if strategy.is_response(user):
        return user

    if is_authenticated:
        if not user:
            url = redirect_value or default_redirect
        else:
            url = redirect_value or \
                  strategy.setting('NEW_ASSOCIATION_REDIRECT_URL') or \
                  default_redirect
    elif user:

# Path: social/utils.py
# 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.
#     """
#     # Quick sanity check.
#     if not redirect_to or not isinstance(redirect_to, six.string_types):
#         return None
# 
#     # Heavier security check, don't allow redirection to a different host.
#     netloc = urlparse(redirect_to)[1]
#     if netloc and netloc != host:
#         return None
#     return redirect_to
# 
# def user_is_authenticated(user):
#     if user and hasattr(user, 'is_authenticated'):
#         if isinstance(user.is_authenticated, collections.Callable):
#             authenticated = user.is_authenticated()
#         else:
#             authenticated = user.is_authenticated
#     elif user:
#         authenticated = True
#     else:
#         authenticated = False
#     return authenticated
# 
# def user_is_active(user):
#     if user and hasattr(user, 'is_active'):
#         if isinstance(user.is_active, collections.Callable):
#             is_active = user.is_active()
#         else:
#             is_active = user.is_active
#     elif user:
#         is_active = True
#     else:
#         is_active = False
#     return is_active


# Path: social/actions.py
from social.p3 import quote
from social.utils import sanitize_redirect, user_is_authenticated, \
                         user_is_active

                      strategy.setting('LOGIN_URL')
    if strategy.session_get('partial_pipeline'):
        idx, backend, xargs, xkwargs = strategy.from_session(
            strategy.session_pop('partial_pipeline')
        )
        if backend == strategy.backend_name:
            kwargs = kwargs.copy()
            kwargs.setdefault('user', user)
            kwargs.update(xkwargs)
            user = strategy.continue_pipeline(pipeline_index=idx,
                                              *xargs, **xkwargs)
        else:
            strategy.clean_partial_pipeline()
            user = strategy.complete(user=user, request=strategy.request,
                                     *args, **kwargs)
    else:
        user = strategy.complete(user=user, request=strategy.request,
                                 *args, **kwargs)

    if strategy.is_response(user):
        return user

    if is_authenticated:
        if not user:
            url = redirect_value or default_redirect
        else:
            url = redirect_value or \
                  strategy.setting('NEW_ASSOCIATION_REDIRECT_URL') or \
                  default_redirect
    elif user:

        if user_is_active(user):