<s> import warnings <EOL> from functools import wraps <EOL> from pyramid . threadlocal import get_current_registry <EOL> from pyramid . httpexceptions import HTTPNotFound , HTTPForbidden <EOL> from social . utils import setting_name , module_member <EOL> from social . strategies . utils import get_strategy <EOL> from social . backends . utils import get_backend , user_backends_data <EOL> DEFAULTS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def get_helper ( name ) : <EOL> settings = get_current_registry ( ) . settings <EOL> return settings . get ( setting_name ( name ) , DEFAULTS . get ( name , None ) ) <EOL> def load_strategy ( request ) : <EOL> return get_strategy ( <EOL> get_helper ( '<STR_LIT>' ) , <EOL> get_helper ( '<STR_LIT>' ) , <EOL> request <EOL> ) <EOL> def load_backend ( strategy , name , redirect_uri ) : <EOL> backends = get_helper ( '<STR_LIT>' ) <EOL> Backend = get_backend ( backends , name ) <EOL> return Backend ( strategy = strategy , redirect_uri = redirect_uri ) <EOL> def psa ( redirect_uri = None ) : <EOL> def decorator ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapper ( request , * args , ** kwargs ) : <EOL> backend = request . matchdict . get ( '<STR_LIT>' ) <EOL> if not backend : <EOL> return HTTPNotFound ( '<STR_LIT>' ) <EOL> uri = redirect_uri <EOL> if uri and not uri . startswith ( '<STR_LIT:/>' ) : <EOL> uri = request . route_url ( uri , backend = backend ) <EOL> request . strategy = load_strategy ( request ) <EOL> request . backend = load_backend ( request . strategy , backend , uri ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return wrapper <EOL> return decorator <EOL> def login_required ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapper ( request , * args , ** kwargs ) : <EOL> is_logged_in = module_member ( <EOL> request . backend . setting ( '<STR_LIT>' ) <EOL> ) <EOL> if not is_logged_in ( request ) : <EOL> raise HTTPForbidden ( '<STR_LIT>' ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return wrapper <EOL> def backends ( request , user ) : <EOL> """<STR_LIT>""" <EOL> storage = module_member ( get_helper ( '<STR_LIT>' ) ) <EOL> return { <EOL> '<STR_LIT>' : user_backends_data ( <EOL> user , get_helper ( '<STR_LIT>' ) , storage <EOL> ) <EOL> } <EOL> def strategy ( * args , ** kwargs ) : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> return psa ( * args , ** kwargs ) </s>
