<s> import base64 <EOL> from openid . association import Association <EOL> from openid . store . interface import OpenIDStore <EOL> from socialregistration . contrib . openid . models import ( OpenIDNonce , <EOL> OpenIDStore as OpenIDStoreModel ) <EOL> class OpenIDStore ( OpenIDStore ) : <EOL> max_nonce_age = <NUM_LIT:6> * <NUM_LIT> * <NUM_LIT> <EOL> def storeAssociation ( self , server_url , assoc = None ) : <EOL> stored_assoc = OpenIDStoreModel . objects . create ( <EOL> server_url = server_url , <EOL> handle = assoc . handle , <EOL> secret = base64 . encodestring ( assoc . secret ) , <EOL> issued = assoc . issued , <EOL> lifetime = assoc . issued , <EOL> assoc_type = assoc . assoc_type <EOL> ) <EOL> def getAssociation ( self , server_url , handle = None ) : <EOL> stored_assocs = OpenIDStoreModel . objects . filter ( <EOL> server_url = server_url <EOL> ) <EOL> if handle : <EOL> stored_assocs = stored_assocs . filter ( handle = handle ) <EOL> stored_assocs . order_by ( '<STR_LIT>' ) <EOL> if stored_assocs . count ( ) == <NUM_LIT:0> : <EOL> return None <EOL> return_val = None <EOL> for stored_assoc in stored_assocs : <EOL> assoc = Association ( <EOL> stored_assoc . handle , base64 . decodestring ( stored_assoc . secret ) , <EOL> stored_assoc . issued , stored_assoc . lifetime , stored_assoc . assoc_type <EOL> ) <EOL> if assoc . getExpiresIn ( ) == <NUM_LIT:0> : <EOL> stored_assoc . delete ( ) <EOL> else : <EOL> if return_val is None : <EOL> return_val = assoc <EOL> return return_val <EOL> def removeAssociation ( self , server_url , handle ) : <EOL> stored_assocs = OpenIDStoreModel . objects . filter ( <EOL> server_url = server_url <EOL> ) <EOL> if handle : <EOL> stored_assocs = stored_assocs . filter ( handle = handle ) <EOL> stored_assocs . delete ( ) <EOL> def useNonce ( self , server_url , timestamp , salt ) : <EOL> try : <EOL> nonce = OpenIDNonce . objects . get ( <EOL> server_url = server_url , <EOL> timestamp = timestamp , <EOL> salt = salt <EOL> ) <EOL> except OpenIDNonce . DoesNotExist : <EOL> nonce = OpenIDNonce . objects . create ( <EOL> server_url = server_url , <EOL> timestamp = timestamp , <EOL> salt = salt <EOL> ) <EOL> return True <EOL> return False </s>
