<s> """<STR_LIT>""" <EOL> import logging <EOL> import socket <EOL> import sys <EOL> import webbrowser <EOL> import gflags <EOL> from oauth2client import client <EOL> from oauth2client import util <EOL> from tools import ClientRedirectHandler <EOL> from tools import ClientRedirectServer <EOL> FLAGS = gflags . FLAGS <EOL> gflags . DEFINE_boolean ( '<STR_LIT>' , True , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> gflags . DEFINE_string ( '<STR_LIT>' , '<STR_LIT:localhost>' , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> gflags . DEFINE_multi_int ( '<STR_LIT>' , [ <NUM_LIT> , <NUM_LIT> ] , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> @ util . positional ( <NUM_LIT:2> ) <EOL> def run ( flow , storage , http = None ) : <EOL> """<STR_LIT>""" <EOL> logging . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if FLAGS . auth_local_webserver : <EOL> success = False <EOL> port_number = <NUM_LIT:0> <EOL> for port in FLAGS . auth_host_port : <EOL> port_number = port <EOL> try : <EOL> httpd = ClientRedirectServer ( ( FLAGS . auth_host_name , port ) , <EOL> ClientRedirectHandler ) <EOL> except socket . error , e : <EOL> pass <EOL> else : <EOL> success = True <EOL> break <EOL> FLAGS . auth_local_webserver = success <EOL> if not success : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print <EOL> print '<STR_LIT>' , <EOL> print '<STR_LIT>' <EOL> print <EOL> if FLAGS . auth_local_webserver : <EOL> oauth_callback = '<STR_LIT>' % ( FLAGS . auth_host_name , port_number ) <EOL> else : <EOL> oauth_callback = client . OOB_CALLBACK_URN <EOL> flow . redirect_uri = oauth_callback <EOL> authorize_url = flow . step1_get_authorize_url ( ) <EOL> if FLAGS . auth_local_webserver : <EOL> webbrowser . open ( authorize_url , new = <NUM_LIT:1> , autoraise = True ) <EOL> print '<STR_LIT>' <EOL> print <EOL> print '<STR_LIT:U+0020>' + authorize_url <EOL> print <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print <EOL> print '<STR_LIT>' <EOL> print <EOL> else : <EOL> print '<STR_LIT>' <EOL> print <EOL> print '<STR_LIT:U+0020>' + authorize_url <EOL> print <EOL> code = None <EOL> if FLAGS . auth_local_webserver : <EOL> httpd . handle_request ( ) <EOL> if '<STR_LIT:error>' in httpd . query_params : <EOL> sys . exit ( '<STR_LIT>' ) <EOL> if '<STR_LIT:code>' in httpd . query_params : <EOL> code = httpd . query_params [ '<STR_LIT:code>' ] <EOL> else : <EOL> print '<STR_LIT>' <EOL> sys . exit ( '<STR_LIT>' ) <EOL> else : <EOL> code = raw_input ( '<STR_LIT>' ) . strip ( ) <EOL> try : <EOL> credential = flow . step2_exchange ( code , http = http ) <EOL> except client . FlowExchangeError , e : <EOL> sys . exit ( '<STR_LIT>' % e ) <EOL> storage . put ( credential ) <EOL> credential . set_store ( storage ) <EOL> print '<STR_LIT>' <EOL> return credential </s>
