
                         >    d Z ddlmZ  G d dej                        Zy)z*Dictionary storage for OAuth2 Credentials.    )clientc                   6     e Zd ZdZd fd	Zd Zd Zd Z xZS )DictionaryStoragea  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                 J    t         t        |   |       || _        || _        y)z'Construct a DictionaryStorage instance.)lockN)superr   __init___dictionary_key)self
dictionarykeyr   	__class__s       :lib/third_party/oauth2client/contrib/dictionary_storage.pyr	   zDictionaryStorage.__init__    s%    /T/:%	    c                     | j                   j                  | j                        }|yt        j                  j                  |      }|j                  |        |S )zRetrieve the credentials from the dictionary, if they exist.

        Returns: A :class:`oauth2client.client.OAuth2Credentials` instance.
        N)r
   getr   r   OAuth2Credentials	from_json	set_store)r   
serializedcredentialss      r   
locked_getzDictionaryStorage.locked_get&   sQ    
 %%))$))4
..88Dd#r   c                 V    |j                         }|| j                  | j                  <   y)zSave the credentials to the dictionary.

        Args:
            credentials: A :class:`oauth2client.client.OAuth2Credentials`
                         instance.
        N)to_jsonr
   r   )r   r   r   s      r   
locked_putzDictionaryStorage.locked_put5   s&     !((*
&0#r   c                 P    | j                   j                  | j                  d       y)z:Remove the credentials from the dictionary, if they exist.N)r
   popr   )r   s    r   locked_deletezDictionaryStorage.locked_delete?   s    TYY-r   )N)	__name__
__module____qualname____doc__r	   r   r   r   __classcell__)r   s   @r   r   r      s    	1.r   r   N)r#   oauth2clientr   Storager    r   r   <module>r(      s    1 -. -.r   