U
    	ڲg                     @   sV   d Z ddlmZ dZdgZddlZddlZddlmZ ddl	m
Z
 dg dfddZdS )	zdUtilities for making samples.

Consolidates a lot of code commonly repeated in sample applications.
    )absolute_importz$jcgregorio@google.com (Joe Gregorio)initN)	discovery)
build_httpc              	   C   s4  zddl m}m}	m}
 W n tk
r4   tdY nX |dkrFd| }|
jg}|| tj|tj	|d}|
| dd }tjtj|d}|j|||
|d	}|	|d
 }| }|dks|jr|
|||}|jt d}|dkrtj|||d}n(t|}tj| d|d}W 5 Q R X ||fS )aj  A common initialization routine for samples.

    Many of the sample applications do the same initialization, which has now
    been consolidated into this function. This function uses common idioms found
    in almost all the samples, i.e. for an API with name 'apiname', the
    credentials are stored in a file named apiname.dat, and the
    client_secrets.json file is stored in the same directory as the application
    main file.

    Args:
      argv: list of string, the command-line parameters of the application.
      name: string, name of the API.
      version: string, version of the API.
      doc: string, description of the application. Usually set to __doc__.
      file: string, filename of the application. Usually set to __file__.
      parents: list of argparse.ArgumentParser, additional command-line flags.
      scope: string, The OAuth scope used.
      discovery_filename: string, name of local discovery file (JSON). Use when discovery doc not available via URL.

    Returns:
      A tuple of (service, flags), where service is the service object and flags
      is the parsed command-line flags.
    r   )clientfiletoolsz^googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.Nz https://www.googleapis.com/auth/)descriptionformatter_classparents   zclient_secrets.json)scopemessagez.dat)httpzhttps://www.googleapis.com/)baser   )Zoauth2clientr   r   r   ImportErrorZ	argparserextendargparseArgumentParserRawDescriptionHelpFormatter
parse_argsospathjoindirnameZflow_from_clientsecretsZmessage_if_missingZStoragegetinvalidZrun_flowZ	authorizer   r   buildopenZbuild_from_documentread)argvnameversiondocfilenamer   r   Zdiscovery_filenamer   r   r   Zparent_parsersparserflagsZclient_secretsZflowZstoragecredentialsr   ZserviceZdiscovery_file r(   @/tmp/pip-unpacked-wheel-rfrvjkbl/googleapiclient/sample_tools.pyr       sH    

  

  )__doc__
__future__r   
__author____all__r   r   Zgoogleapiclientr   Zgoogleapiclient.httpr   r   r(   r(   r(   r)   <module>   s     