<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import logging <EOL> import socket <EOL> import sys <EOL> from six . moves import BaseHTTPServer <EOL> from six . moves import http_client <EOL> from six . moves import urllib <EOL> from six . moves import input <EOL> from oauth2client import client <EOL> from oauth2client import util <EOL> __author__ = '<STR_LIT>' <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> _CLIENT_SECRETS_MESSAGE = """<STR_LIT>""" <EOL> def _CreateArgumentParser ( ) : <EOL> try : <EOL> import argparse <EOL> except ImportError : <EOL> return None <EOL> parser = argparse . ArgumentParser ( add_help = False ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT:localhost>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> default = False , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = [ <NUM_LIT> , <NUM_LIT> ] , type = int , <EOL> nargs = '<STR_LIT:*>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , default = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> help = '<STR_LIT>' ) <EOL> return parser <EOL> argparser = _CreateArgumentParser ( ) <EOL> class ClientRedirectServer ( BaseHTTPServer . HTTPServer ) : <EOL> """<STR_LIT>""" <EOL> query_params = { } <EOL> class ClientRedirectHandler ( BaseHTTPServer . BaseHTTPRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def do_GET ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send_response ( http_client . OK ) <EOL> self . send_header ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . end_headers ( ) <EOL> query = self . path . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> query = dict ( urllib . parse . parse_qsl ( query ) ) <EOL> self . server . query_params = query <EOL> self . wfile . write ( <EOL> b"<STR_LIT>" ) <EOL> self . wfile . write ( <EOL> b"<STR_LIT>" ) <EOL> self . wfile . write ( b"<STR_LIT>" ) <EOL> def log_message ( self , format , * args ) : <EOL> """<STR_LIT>""" <EOL> @ util . positional ( <NUM_LIT:3> ) <EOL> def run_flow ( flow , storage , flags , http = None ) : <EOL> """<STR_LIT>""" <EOL> logging . getLogger ( ) . setLevel ( getattr ( logging , flags . logging_level ) ) <EOL> if not flags . noauth_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 : <EOL> pass <EOL> else : <EOL> success = True <EOL> break <EOL> flags . noauth_local_webserver = not success <EOL> if not success : <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( ) <EOL> if not flags . noauth_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 not flags . noauth_local_webserver : <EOL> import webbrowser <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> '<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 not flags . noauth_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> '<STR_LIT>' ) <EOL> sys . exit ( '<STR_LIT>' ) <EOL> else : <EOL> code = input ( '<STR_LIT>' ) . strip ( ) <EOL> try : <EOL> credential = flow . step2_exchange ( code , http = http ) <EOL> except client . FlowExchangeError as e : <EOL> sys . exit ( '<STR_LIT>' % e ) <EOL> storage . put ( credential ) <EOL> credential . set_store ( storage ) <EOL> print ( '<STR_LIT>' ) <EOL> return credential <EOL> def message_if_missing ( filename ) : <EOL> """<STR_LIT>""" <EOL> return _CLIENT_SECRETS_MESSAGE % filename </s>
