<s> from __future__ import unicode_literals <EOL> from django . core import signing <EOL> from django . utils . encoding import smart_text <EOL> class TokenGenerator ( object ) : <EOL> def _uid ( self , user ) : <EOL> raise NotImplementedError <EOL> def generate ( self , user , data = None ) : <EOL> """<STR_LIT>""" <EOL> data = data or { } <EOL> data . update ( { '<STR_LIT>' : self . _uid ( user ) , } ) <EOL> return signing . dumps ( data , salt = __name__ ) . replace ( "<STR_LIT::>" , "<STR_LIT:.>" ) <EOL> def is_valid ( self , user , signed_value ) : <EOL> try : <EOL> self . data = signing . loads ( signed_value . replace ( "<STR_LIT:.>" , "<STR_LIT::>" ) , salt = __name__ ) <EOL> except signing . BadSignature : <EOL> return False <EOL> if self . data [ '<STR_LIT>' ] != self . _uid ( user ) : <EOL> return False <EOL> return True <EOL> class UserActivationTokenGenerator ( TokenGenerator ) : <EOL> def _uid ( self , user ) : <EOL> return "<STR_LIT:;>" . join ( ( smart_text ( user . pk ) , smart_text ( user . st . is_verified ) ) ) <EOL> class UserEmailChangeTokenGenerator ( TokenGenerator ) : <EOL> def _uid ( self , user ) : <EOL> return "<STR_LIT:;>" . join ( ( smart_text ( user . pk ) , smart_text ( user . email ) ) ) <EOL> def generate ( self , user , new_email ) : <EOL> return super ( UserEmailChangeTokenGenerator , self ) . generate ( user , { '<STR_LIT>' : new_email , } ) <EOL> def get_email ( self ) : <EOL> return self . data [ '<STR_LIT>' ] </s>
