
                             d Z ddlZddlZdZdZeg dddgdeg dddgdiZ G d	 d
e      Z G d de      Zd Z	d Z
d Zd ZddZy)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.
    Nweb	installed)	client_idclient_secretredirect_urisauth_uri	token_urir   r   )requiredstringc                       e Zd ZdZy)ErrorzBase error for this module.N__name__
__module____qualname____doc__     9platform/bq/third_party/oauth2client_4_0/clientsecrets.pyr   r   =   s    %r   r   c                       e Zd ZdZy)InvalidClientSecretsErrorz(Format of ClientSecrets file is invalid.Nr   r   r   r   r   r   A   s    2r   r   c                    d}| t        |      	 | j                         \  \  }}|t        vrt        dj                  |            t        |   d   D ]!  }||vst        dj                  ||             t        |   d   D ]0  }||   j                  d      st        dj                  |             ||fS # t        t        f$ r t        |dz         w xY w)	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&>&>&@#"k ,&''..{;= 	= "+.z:	K'+CJJ{,- - ;
 "+.x8	y!,,T2+3::9EG G 9 ##' ' ''$ (& &' 	''s   B; ;Cc                 B    t        j                  |       }t        |      S N)jsonloadr$   )fpobjs     r   r(   r(   n   s    
))B-C"3''r   c                 B    t        j                  |       }t        |      S r&   )r'   loadsr$   )sr*   s     r   r,   r,   s   s    
**Q-C"3''r   c                     	 t        | d      5 }t        j                  |      }d d d        t              S # 1 sw Y   xY w# t        $ r1}t	        d|j
                  |j                  |j                        d }~ww xY w)NrzError opening file)	openr'   r(   IOErrorr   filenamestrerrorerrnor$   )r2   r)   r*   excs       r   	_loadfiler6   x   sr    A(C B))B-C !
 #3'' !  A'(<cll(+ciiA 	AAs*   A 7A A A 	A=,A88A=c                     d}|st        |       S |j                  | |      }|&t        |       \  }}||i}|j                  | ||       t        t	        j
                  |            S )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)r6   getsetnextsix	iteritems)r2   cache_SECRET_NAMESPACEr*   r!   r"   s         r   loadfiler@      sq    B 2""
))H(9)
:C
{#,X#6 [K(		(C+<	=c"##r   r&   )r   r'   r<   TYPE_WEBTYPE_INSTALLEDr   	Exceptionr   r   r$   r(   r,   r6   r@   r   r   r   <module>rD      s      
  
 
 
 
<&I &3 3&$R(
(
(,$r   