<s> from social . exceptions import MissingBackend <EOL> from social . backends . base import BaseAuth <EOL> from social . utils import module_member , user_is_authenticated <EOL> BACKENDSCACHE = { } <EOL> def load_backends ( backends , force_load = False ) : <EOL> """<STR_LIT>""" <EOL> global BACKENDSCACHE <EOL> if force_load : <EOL> BACKENDSCACHE = { } <EOL> if not BACKENDSCACHE : <EOL> for auth_backend in backends : <EOL> backend = module_member ( auth_backend ) <EOL> if issubclass ( backend , BaseAuth ) : <EOL> BACKENDSCACHE [ backend . name ] = backend <EOL> return BACKENDSCACHE <EOL> def get_backend ( backends , name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return BACKENDSCACHE [ name ] <EOL> except KeyError : <EOL> load_backends ( backends , force_load = True ) <EOL> try : <EOL> return BACKENDSCACHE [ name ] <EOL> except KeyError : <EOL> raise MissingBackend ( name ) <EOL> def user_backends_data ( user , backends , storage ) : <EOL> """<STR_LIT>""" <EOL> available = list ( load_backends ( backends ) . keys ( ) ) <EOL> values = { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : available , <EOL> '<STR_LIT>' : available } <EOL> if user_is_authenticated ( user ) : <EOL> associated = storage . user . get_social_auth_for_user ( user ) <EOL> not_associated = list ( set ( available ) - <EOL> set ( assoc . provider for assoc in associated ) ) <EOL> values [ '<STR_LIT>' ] = associated <EOL> values [ '<STR_LIT>' ] = not_associated <EOL> return values </s>
