
    
                     Z    d Z ddlZddlZddlmZ ddlmZ  G d dej                        Zy)zYUtilities for OAuth.

Utilities for making it easier to work with OAuth 2.0
credentials.
    N)_helpers)clientc                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )Storagez:Store and retrieve a single credential to and from a file.c                 `    t         t        |   t        j                                || _        y )N)lock)superr   __init__	threadingLock	_filename)selffilename	__class__s     0platform/bq/third_party/oauth2client_4_0/file.pyr
   zStorage.__init__    s#    gt%9>>+;%<!    c                 Z   d}t        j                  | j                         	 t        | j                  d      }|j	                         }|j                          	 t        j                  j                  |      }|j                  |        |S # t        $ r |cY S w xY w# t        $ r Y |S w xY w)zRetrieve Credential from file.

        Returns:
            oauth2client_4_0.client.Credentials

        Raises:
            IOError if the file is a symbolic link.
        Nrb)r   validate_filer   openreadcloseIOErrorr   Credentialsnew_from_json	set_store
ValueError)r   credentialsfcontents       r   
locked_getzStorage.locked_get$   s     t~~.	T^^T*AffhGGGI	 ,,::7CK!!$'   		  		s#   6B 0B BB	B*)B*c                 *   t         j                  j                  | j                        sPt        j                  d      }	 t        | j                  d      j                          t        j                  |       yy# t        j                  |       w xY w)zCreate an empty file if necessary.

        This method will not initialize the file. Instead it implements a
        simple version of "touch" to ensure the file has been created.
           za+bN)ospathexistsr   umaskr   r   )r   	old_umasks     r   _create_file_if_neededzStorage._create_file_if_needed>   sb     ww~~dnn-I$T^^U+113# .
 #s    $A; ;Bc                     | j                          t        j                  | j                         t	        | j                  d      }|j                  |j                                |j                          y)zWrite Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.

        Raises:
            IOError if the file is a symbolic link.
        wN)r)   r   r   r   r   writeto_jsonr   )r   r   r   s      r   
locked_putzStorage.locked_putK   sP     	##%t~~.%	##%&		r   c                 B    t        j                  | j                         y)zpDelete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        N)r$   unlinkr   )r   s    r   locked_deletezStorage.locked_deleteZ   s     			$..!r   )
__name__
__module____qualname____doc__r
   r!   r)   r.   r1   __classcell__)r   s   @r   r   r      s    D"4$"r   r   )r5   r$   r   oauth2client_4_0r   r   r    r   r   <module>r9      s*     
  % #C"fnn C"r   