<s> from collections import defaultdict <EOL> from social . apps . django_app . context_processors import login_redirect , backends , LazyDict <EOL> from social . backends . oauth import BaseOAuth1 , BaseOAuth2 <EOL> from social . backends . open_id import OpenIdAuth <EOL> from social . utils import user_is_authenticated <EOL> from social_auth . models import UserSocialAuth <EOL> from social_auth . backends import get_backends <EOL> def social_auth_backends ( request ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : backends ( request ) } <EOL> def social_auth_by_type_backends ( request ) : <EOL> """<STR_LIT>""" <EOL> def context_value ( ) : <EOL> data = dict ( backends ( request ) [ '<STR_LIT>' ] ) <EOL> data [ '<STR_LIT>' ] = group_backend_by_type ( data [ '<STR_LIT>' ] ) <EOL> data [ '<STR_LIT>' ] = group_backend_by_type ( data [ '<STR_LIT>' ] ) <EOL> data [ '<STR_LIT>' ] = group_backend_by_type ( data [ '<STR_LIT>' ] ) <EOL> return data <EOL> return { '<STR_LIT>' : LazyDict ( context_value ) } <EOL> def social_auth_by_name_backends ( request ) : <EOL> """<STR_LIT>""" <EOL> def context_value ( ) : <EOL> keys = [ key for key in get_backends ( ) . keys ( ) ] <EOL> accounts = dict ( zip ( keys , [ None ] * len ( keys ) ) ) <EOL> user = request . user <EOL> if user_is_authenticated ( user ) : <EOL> accounts . update ( ( assoc . provider , assoc ) <EOL> for assoc in UserSocialAuth . get_social_auth_for_user ( user ) ) <EOL> return accounts <EOL> return { '<STR_LIT>' : LazyDict ( context_value ) } <EOL> def social_auth_login_redirect ( request ) : <EOL> """<STR_LIT>""" <EOL> data = login_redirect ( request ) <EOL> data [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' ) <EOL> return data <EOL> def group_backend_by_type ( items ) : <EOL> """<STR_LIT>""" <EOL> result = defaultdict ( list ) <EOL> backends_defined = get_backends ( ) <EOL> for item in items : <EOL> name = getattr ( item , '<STR_LIT>' , item ) <EOL> backend = backends_defined [ name ] <EOL> if issubclass ( backend , OpenIdAuth ) : <EOL> result [ '<STR_LIT>' ] . append ( item ) <EOL> elif issubclass ( backend , BaseOAuth2 ) : <EOL> result [ '<STR_LIT>' ] . append ( item ) <EOL> elif issubclass ( backend , BaseOAuth1 ) : <EOL> result [ '<STR_LIT>' ] . append ( item ) <EOL> return dict ( result ) </s>
