
                             S r SSKrSSKrSrSrSr\/ SQSS/S	.\/ SQSS/S	.0r " S
 S\5      r " S S\5      r	S r
S rS rS rSS jrg)zUtilities for reading OAuth 2.0 client secret files.

A client_secrets.json file contains all the information needed to interact with
an OAuth 2.0 protected service.
    Nz$jcgregorio@google.com (Joe Gregorio)web	installed)	client_idclient_secretredirect_urisauth_uri	token_urir   r   )requiredstringc                       \ rS rSrSrSrg)Error=   zBase error for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       -lib/third_party/oauth2client/clientsecrets.pyr   r   =   s    %r   r   c                       \ rS rSrSrSrg)InvalidClientSecretsErrorA   z(Format of ClientSecrets file is invalid.r   Nr   r   r   r   r   r   A   s    2r   r   c                    SnU c  [        U5      e U R                  5       u  u  p#U[        ;  a  [        SR                  U5      5      e[        U   S    H"  nXC;  d  M
  [        SR                  XB5      5      e   [        U   S    H5  nX4   R                  S5      (       d  M  [        SR                  U5      5      e   X#4$ ! [        [        4 a    [        US-   5      ef = f)	zValidate parsed client secrets from a file.

Args:
    clientsecrets_dict: dict, a dictionary holding the client secrets.

Returns:
    tuple, a string of the client type and the information parsed
    from the file.
ziInvalid file format. See https://developers.google.com/api-client-library/python/guide/aaa_client_secretszU Expected a JSON object with a single property for a "web" or "installed" applicationzUnknown client type: {0}.r
   z1Missing property "{0}" in a client type of "{1}".r   z[[z!Property "{0}" is not configured.)r   items
ValueErrorAttributeErrorVALID_CLIENTformat
startswith)clientsecrets_dict_INVALID_FILE_FORMAT_MSGclient_typeclient_info	prop_names        r   _validate_clientsecretsr(   E   s   	* 
 !'(@AA'&8&>&>&@#" ,&''..{;= 	= "+.z:	'+CJJ,- - ;
 "+.x8	!,,T22+3::9EG G 9 ##' ' ''$ (& &' 	''s   C C#c                 D    [         R                  " U 5      n[        U5      $ N)jsonloadr(   )fpobjs     r   r,   r,   n   s    
))B-C"3''r   c                 D    [         R                  " U 5      n[        U5      $ r*   )r+   loadsr(   )sr.   s     r   r0   r0   s   s    
**Q-C"3''r   c                     [        U S5       n[        R                  " U5      nS S S 5        [        W5      $ ! , (       d  f       N= f! [         a1  n[	        SUR
                  UR                  UR                  5      eS nAff = f)NrzError opening file)	openr+   r,   IOErrorr   filenamestrerrorerrnor(   )r6   r-   r.   excs       r   	_loadfiler:   x   sr    A(C B))B-C !
 #3'' !  A'(<cll(+ciiA 	AAs1   A	 8A	 
AA	 A	 	
B,A??Bc                     SnU(       d  [        U 5      $ UR                  XS9nUc   [        U 5      u  pEXE0nUR                  XUS9  [        [        R
                  " U5      5      $ )a?  Loading of client_secrets JSON file, optionally backed by a cache.

Typical cache storage would be App Engine memcache service,
but you can pass in any other cache client that implements
these methods:

* ``get(key, namespace=ns)``
* ``set(key, value, namespace=ns)``

Usage::

    # without caching
    client_type, client_info = loadfile('secrets.json')
    # using App Engine memcache service
    from google.appengine.api import memcache
    client_type, client_info = loadfile('secrets.json', cache=memcache)

Args:
    filename: string, Path to a client_secrets.json file on a filesystem.
    cache: An optional cache service client that implements get() and set()
    methods. If not specified, the file is always being loaded from
             a filesystem.

Raises:
    InvalidClientSecretsError: In case of a validation error or some
                               I/O failure. Can happen only on cache miss.

Returns:
    (client_type, client_info) tuple, as _loadfile() normally would.
    JSON contents is validated only during first load. Cache hits are not
    validated.
zoauth2client:secrets#ns)	namespace)r:   getsetnextsix	iteritems)r6   cache_SECRET_NAMESPACEr.   r%   r&   s         r   loadfilerD      sh    B 2""
))H)
:C
{#,X#6 (		(+<	=c"##r   r*   )r   r+   r@   
__author__TYPE_WEBTYPE_INSTALLEDr    	Exceptionr   r   r(   r,   r0   r:   rD   r   r   r   <module>rI      s     
3
  
 
 
 
<&I &3 3&$R(
(
(,$r   