<s> import time <EOL> import random <EOL> import hashlib <EOL> from social . utils import setting_name , module_member <EOL> from social . store import OpenIdStore , OpenIdSessionWrapper <EOL> from social . pipeline import DEFAULT_AUTH_PIPELINE , DEFAULT_DISCONNECT_PIPELINE <EOL> from social . pipeline . utils import partial_from_session , partial_to_session <EOL> class BaseTemplateStrategy ( object ) : <EOL> def __init__ ( self , strategy ) : <EOL> self . strategy = strategy <EOL> def render ( self , tpl = None , html = None , context = None ) : <EOL> if not tpl and not html : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> context = context or { } <EOL> if tpl : <EOL> return self . render_template ( tpl , context ) <EOL> else : <EOL> return self . render_string ( html , context ) <EOL> def render_template ( self , tpl , context ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def render_string ( self , html , context ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> class BaseStrategy ( object ) : <EOL> ALLOWED_CHARS = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> DEFAULT_TEMPLATE_STRATEGY = BaseTemplateStrategy <EOL> def __init__ ( self , storage = None , tpl = None ) : <EOL> self . storage = storage <EOL> self . tpl = ( tpl or self . DEFAULT_TEMPLATE_STRATEGY ) ( self ) <EOL> def setting ( self , name , default = None , backend = None ) : <EOL> names = [ setting_name ( name ) , name ] <EOL> if backend : <EOL> names . insert ( <NUM_LIT:0> , setting_name ( backend . name , name ) ) <EOL> for name in names : <EOL> try : <EOL> return self . get_setting ( name ) <EOL> except ( AttributeError , KeyError ) : <EOL> pass <EOL> return default <EOL> def create_user ( self , * args , ** kwargs ) : <EOL> return self . storage . user . create_user ( * args , ** kwargs ) <EOL> def get_user ( self , * args , ** kwargs ) : <EOL> return self . storage . user . get_user ( * args , ** kwargs ) <EOL> def session_setdefault ( self , name , value ) : <EOL> self . session_set ( name , value ) <EOL> return self . session_get ( name ) <EOL> def openid_session_dict ( self , name ) : <EOL> return OpenIdSessionWrapper ( self . session_setdefault ( name , { } ) ) <EOL> def to_session_value ( self , val ) : <EOL> return val <EOL> def from_session_value ( self , val ) : <EOL> return val <EOL> def partial_to_session ( self , next , backend , request = None , * args , ** kwargs ) : <EOL> return partial_to_session ( self , next , backend , request = request , <EOL> * args , ** kwargs ) <EOL> def partial_from_session ( self , session ) : <EOL> return partial_from_session ( self , session ) <EOL> def clean_partial_pipeline ( self , name = '<STR_LIT>' ) : <EOL> self . session_pop ( name ) <EOL> def openid_store ( self ) : <EOL> return OpenIdStore ( self ) <EOL> def get_pipeline ( self ) : <EOL> return self . setting ( '<STR_LIT>' , DEFAULT_AUTH_PIPELINE ) <EOL> def get_disconnect_pipeline ( self ) : <EOL> return self . setting ( '<STR_LIT>' , DEFAULT_DISCONNECT_PIPELINE ) <EOL> def random_string ( self , length = <NUM_LIT:12> , chars = ALLOWED_CHARS ) : <EOL> try : <EOL> random . SystemRandom ( ) <EOL> except NotImplementedError : <EOL> key = self . setting ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> seed = '<STR_LIT>' . format ( random . getstate ( ) , time . time ( ) , key ) <EOL> random . seed ( hashlib . sha256 ( seed . encode ( ) ) . digest ( ) ) <EOL> return '<STR_LIT>' . join ( [ random . choice ( chars ) for i in range ( length ) ] ) <EOL> def absolute_uri ( self , path = None ) : <EOL> uri = self . build_absolute_uri ( path ) <EOL> if uri and self . setting ( '<STR_LIT>' ) : <EOL> uri = uri . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return uri <EOL> def get_language ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def send_email_validation ( self , backend , email ) : <EOL> email_validation = self . setting ( '<STR_LIT>' ) <EOL> send_email = module_member ( email_validation ) <EOL> code = self . storage . code . make_code ( email ) <EOL> send_email ( self , backend , code ) <EOL> return code <EOL> def validate_email ( self , email , code ) : <EOL> verification_code = self . storage . code . get_code ( code ) <EOL> if not verification_code or verification_code . code != code : <EOL> return False <EOL> else : <EOL> verification_code . verify ( ) <EOL> return True <EOL> def render_html ( self , tpl = None , html = None , context = None ) : <EOL> """<STR_LIT>""" <EOL> return self . tpl . render ( tpl , html , context ) <EOL> def authenticate ( self , backend , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ '<STR_LIT>' ] = self <EOL> kwargs [ '<STR_LIT>' ] = self . storage <EOL> kwargs [ '<STR_LIT>' ] = backend <EOL> return backend . authenticate ( * args , ** kwargs ) <EOL> def get_backends ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . setting ( '<STR_LIT>' , [ ] ) <EOL> def redirect ( self , url ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def get_setting ( self , name ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def html ( self , content ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_data ( self , merge = True ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_host ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def session_get ( self , name , default = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def session_set ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def session_pop ( self , name ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def build_absolute_uri ( self , path = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_is_secure ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_path ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_port ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_get ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def request_post ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) </s>
