ó
‚¾^Yc           @   sä   d  Z  d d l Z d d l Z d Z d Z i i d d d d d	 g d
 6d d g d 6e 6i d d d d d	 g d
 6d d g d 6e 6Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z	 d „  Z
 d „  Z d „  Z d d „ Z d S(   s¦   Utilities 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.
iÿÿÿÿNt   webt	   installedt	   client_idt   client_secrett   redirect_urist   auth_urit	   token_urit   requiredt   stringt   Errorc           B   s   e  Z d  Z RS(   s   Base error for this module.(   t   __name__t
   __module__t   __doc__(    (    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyR	   <   s   t   InvalidClientSecretsErrorc           B   s   e  Z d  Z RS(   s(   Format of ClientSecrets file is invalid.(   R
   R   R   (    (    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyR   @   s   c         C   s  d } |  d	 k r! t | ƒ ‚ n  y |  j ƒ  \ \ } } Wn' t t f k
 rc t | d ƒ ‚ n X| t k rˆ t d j | ƒ ƒ ‚ n  x= t | d D]- } | | k r— t d j | | ƒ ƒ ‚ q— q— WxA t | d D]1 } | | j d ƒ r× t d j | ƒ ƒ ‚ q× q× W| | f S(
   sñ   Validate 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.
    si   Invalid file format. See https://developers.google.com/api-client-library/python/guide/aaa_client_secretssU    Expected a JSON object with a single property for a "web" or "installed" applications   Unknown client type: {0}.R   s1   Missing property "{0}" in a client type of "{1}".R   s   [[s!   Property "{0}" is not configured.N(   t   NoneR   t   itemst
   ValueErrort   AttributeErrort   VALID_CLIENTt   formatt
   startswith(   t   clientsecrets_dictt   _INVALID_FILE_FORMAT_MSGt   client_typet   client_infot	   prop_name(    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyt   _validate_clientsecretsD   s*    c         C   s   t  j |  ƒ } t | ƒ S(   N(   t   jsont   loadR   (   t   fpt   obj(    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyR   m   s    c         C   s   t  j |  ƒ } t | ƒ S(   N(   R   t   loadsR   (   t   sR   (    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyR   r   s    c         C   si   y+ t  |  d ƒ  } t j | ƒ } Wd  QXWn1 t k
 r^ } t d | j | j | j ƒ ‚ n Xt | ƒ S(   Nt   rs   Error opening file(	   t   openR   R   t   IOErrorR   t   filenamet   strerrort   errnoR   (   R$   R   R   t   exc(    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyt	   _loadfilew   s    c         C   s‚   d } | s t  |  ƒ S| j |  d | ƒ} | d k ro t  |  ƒ \ } } i | | 6} | j |  | d | ƒn  t t j | ƒ ƒ S(   sŸ  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.
    s   oauth2client:secrets#nst	   namespaceN(   R(   t   getR   t   sett   nextt   sixt	   iteritems(   R$   t   cachet   _SECRET_NAMESPACER   R   R   (    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyt   loadfile   s    !
(   R   R   R-   t   TYPE_WEBt   TYPE_INSTALLEDR   t	   ExceptionR	   R   R   R   R   R(   R   R1   (    (    (    s@   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/clientsecrets.pyt   <module>   s8   

	)			
