<s> from __future__ import print_function <EOL> import constants , rauth , subprocess , os , json , base64 , urlparse <EOL> """<STR_LIT>""" <EOL> def get_oauth_service ( ) : <EOL> client_id , client_secret = json . loads ( base64 . b64decode ( constants . CLIENT_DATA ) ) <EOL> return rauth . OAuth2Service ( <EOL> client_id = client_id , <EOL> client_secret = client_secret , <EOL> access_token_url = constants . ENDPOINT_ACCESS , <EOL> authorize_url = constants . ENDPOINT_AUTHORIZE , <EOL> base_url = constants . ENDPOINT_BASE ) <EOL> def get_session ( stored_refresh_token ) : <EOL> """<STR_LIT>""" <EOL> service = get_oauth_service ( ) <EOL> r = service . get_raw_access_token ( data = { <EOL> '<STR_LIT>' : stored_refresh_token , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> return service . get_session ( r . json ( ) [ '<STR_LIT>' ] ) <EOL> def access ( authorization_code ) : <EOL> """<STR_LIT>""" <EOL> return get_oauth_service ( ) . get_raw_access_token ( data = { <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : constants . CALLBACK <EOL> } ) . json ( ) [ '<STR_LIT>' ] <EOL> def authorize ( ) : <EOL> """<STR_LIT>""" <EOL> subprocess . call ( [ '<STR_LIT>' , get_oauth_service ( ) . get_authorize_url ( ** constants . AUTHORIZE_DATA ) ] ) <EOL> def main ( callback_final = None ) : <EOL> """<STR_LIT>""" <EOL> if ( callback_final ) : <EOL> print ( json . dumps ( access ( urlparse . parse_qs ( callback_final ) [ '<STR_LIT:code>' ] ) ) , end = '<STR_LIT>' ) <EOL> else : <EOL> print ( json . dumps ( authorize ( ) ) , end = '<STR_LIT>' ) <EOL> exit ( <NUM_LIT:4> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( os . getenv ( '<STR_LIT>' ) ) </s>
