a
    !f                     @   s   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
 d
eZG dd deZdd Z	dd Z
dd Zdd ZdddZdS )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web	installed)	client_idclient_secretZredirect_urisZauth_uriZ	token_urir   r   )requiredstringc                   @   s   e Zd ZdZdS )ErrorzBase error for this module.N__name__
__module____qualname____doc__ r   r   [/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/clientsecrets.pyr   <   s   r   c                   @   s   e Zd ZdZdS )InvalidClientSecretsErrorz(Format of ClientSecrets file is invalid.Nr   r   r   r   r   r   @   s   r   c              	   C   s   d}| du rt |z|  \\}}W n" ttfyH   t |d Y n0 |tvr`t d|t| d D ]}||vrlt d||qlt| d D ] }|| drt d	|q||fS )
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_secretsNzU 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)Zclientsecrets_dictZ_INVALID_FILE_FORMAT_MSGclient_typeclient_infoZ	prop_namer   r   r   _validate_clientsecretsD   s6    
r   c                 C   s   t | }t|S N)jsonloadr   )fpobjr   r   r   r   m   s    
r   c                 C   s   t | }t|S r   )r   loadsr   )sr   r   r   r   r   r   s    
r   c              
   C   sz   z8t | d}t|}W d    n1 s,0    Y  W n8 typ } z td|j|j|jW Y d }~n
d }~0 0 t|S )NrzError opening file)	openr   r   IOErrorr   filenamestrerrorerrnor   )r#   r   r   excr   r   r   	_loadfilew   s    ,r'   c                 C   sX   d}|st | S |j| |d}|du rJt | \}}||i}|j| ||d tt|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)	namespaceN)r'   getsetnextsix	iteritems)r#   cacheZ_SECRET_NAMESPACEr   r   r   r   r   r   loadfile   s    !r/   )N)r   r   r,   ZTYPE_WEBZTYPE_INSTALLEDr   	Exceptionr   r   r   r   r   r'   r/   r   r   r   r   <module>   s0   )
