ó
ū^Yc           @   s3   d  Z  d d l m Z d e j f d     YZ d S(   s*   Dictionary storage for OAuth2 Credentials.iĸĸĸĸ(   t   clientt   DictionaryStoragec           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   sĄ  Store and retrieve credentials to and from a dictionary-like object.

    Args:
        dictionary: A dictionary or dictionary-like object.
        key: A string or other hashable. The credentials will be stored in
             ``dictionary[key]``.
        lock: An optional threading.Lock-like object. The lock will be
              acquired before anything is written or read from the
              dictionary.
    c         C   s/   t  t |   j d |  | |  _ | |  _ d S(   s'   Construct a DictionaryStorage instance.t   lockN(   t   superR   t   __init__t   _dictionaryt   _key(   t   selft
   dictionaryt   keyR   (    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyR       s    	c         C   sH   |  j  j |  j  } | d k r% d St j j |  } | j |   | S(   s   Retrieve the credentials from the dictionary, if they exist.

        Returns: A :class:`oauth2client.client.OAuth2Credentials` instance.
        N(   R   t   getR   t   NoneR    t   OAuth2Credentialst	   from_jsont	   set_store(   R   t
   serializedt   credentials(    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyt
   locked_get&   s    c         C   s    | j    } | |  j |  j <d S(   sŽ   Save the credentials to the dictionary.

        Args:
            credentials: A :class:`oauth2client.client.OAuth2Credentials`
                         instance.
        N(   t   to_jsonR   R   (   R   R   R   (    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyt
   locked_put5   s    c         C   s   |  j  j |  j d  d S(   s:   Remove the credentials from the dictionary, if they exist.N(   R   t   popR   R   (   R   (    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyt   locked_delete?   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyR      s
   
		
N(   R   t   oauth2clientR    t   StorageR   (    (    (    sM   /tmp/pip-build-kpPAdC/oauth2client/oauth2client/contrib/dictionary_storage.pyt   <module>   s   