<s> import jwt <EOL> import uuid <EOL> import warnings <EOL> from calendar import timegm <EOL> from datetime import datetime <EOL> from rest_framework_jwt . compat import get_username , get_username_field <EOL> from rest_framework_jwt . settings import api_settings <EOL> def jwt_payload_handler ( user ) : <EOL> username_field = get_username_field ( ) <EOL> username = get_username ( user ) <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning <EOL> ) <EOL> payload = { <EOL> '<STR_LIT>' : user . pk , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT>' : datetime . utcnow ( ) + api_settings . JWT_EXPIRATION_DELTA <EOL> } <EOL> if isinstance ( user . pk , uuid . UUID ) : <EOL> payload [ '<STR_LIT>' ] = str ( user . pk ) <EOL> payload [ username_field ] = username <EOL> if api_settings . JWT_ALLOW_REFRESH : <EOL> payload [ '<STR_LIT>' ] = timegm ( <EOL> datetime . utcnow ( ) . utctimetuple ( ) <EOL> ) <EOL> if api_settings . JWT_AUDIENCE is not None : <EOL> payload [ '<STR_LIT>' ] = api_settings . JWT_AUDIENCE <EOL> if api_settings . JWT_ISSUER is not None : <EOL> payload [ '<STR_LIT>' ] = api_settings . JWT_ISSUER <EOL> return payload <EOL> def jwt_get_user_id_from_payload_handler ( payload ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning <EOL> ) <EOL> return payload . get ( '<STR_LIT>' ) <EOL> def jwt_get_username_from_payload_handler ( payload ) : <EOL> """<STR_LIT>""" <EOL> return payload . get ( '<STR_LIT:username>' ) <EOL> def jwt_encode_handler ( payload ) : <EOL> return jwt . encode ( <EOL> payload , <EOL> api_settings . JWT_PRIVATE_KEY or api_settings . JWT_SECRET_KEY , <EOL> api_settings . JWT_ALGORITHM <EOL> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> def jwt_decode_handler ( token ) : <EOL> options = { <EOL> '<STR_LIT>' : api_settings . JWT_VERIFY_EXPIRATION , <EOL> } <EOL> return jwt . decode ( <EOL> token , <EOL> api_settings . JWT_PUBLIC_KEY or api_settings . JWT_SECRET_KEY , <EOL> api_settings . JWT_VERIFY , <EOL> options = options , <EOL> leeway = api_settings . JWT_LEEWAY , <EOL> audience = api_settings . JWT_AUDIENCE , <EOL> issuer = api_settings . JWT_ISSUER , <EOL> algorithms = [ api_settings . JWT_ALGORITHM ] <EOL> ) <EOL> def jwt_response_payload_handler ( token , user = None , request = None ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT>' : token <EOL> } </s>
