
                         h    S r SSKrSSKrSSKJr  Sr " S S\5      r " S S\R                  5      rg)	zYUtilities for OAuth.

Utilities for making it easier to work with OAuth 2.0
credentials.
    N)clientz$jcgregorio@google.com (Joe Gregorio)c                       \ rS rSrSrSrg) CredentialsFileSymbolicLinkError   z-Credentials files must not be symbolic links. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       $lib/third_party/oauth2client/file.pyr   r      s    7r   r   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
Storage"   z:Store and retrieve a single credential to and from a file.c                 Z   > [         [        U ]  [        R                  " 5       S9  Xl        g )N)lock)superr   __init__	threadingLock	_filename)selffilename	__class__s     r   r   Storage.__init__%   s!    gt%9>>+;%<!r   c                     [         R                  R                  U R                  5      (       a$  [	        SR                  U R                  5      5      eg )NzFile: {0} is a symbolic link.)ospathislinkr   r   formatr   s    r   _validate_fileStorage._validate_file)   s?    77>>$..))2/66t~~FH H *r   c                 @   SnU R                  5          [        U R                  S5      nUR                  5       nUR	                  5          [        R                  R                  U5      nUR                  U 5        U$ ! [
         a    Us $ f = f! [         a     U$ f = f)zRetrieve Credential from file.

Returns:
    oauth2client.client.Credentials

Raises:
    CredentialsFileSymbolicLinkError if the file is a symbolic link.
Nrb)r$   openr   readcloseIOErrorr   Credentialsnew_from_json	set_store
ValueError)r   credentialsfcontents       r   
locked_getStorage.locked_get.   s     	T^^T*AffhGGGI	 ,,::7CK!!$'   		  		s#   6A= 0B =BB
BBc                 :   [         R                  R                  U R                  5      (       dR  [         R                  " S5      n [        U R                  S5      R                  5         [         R                  " U5        gg! [         R                  " U5        f = f)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)r   r    existsr   umaskr(   r*   )r   	old_umasks     r   _create_file_if_neededStorage._create_file_if_neededH   se     ww~~dnn--I$T^^U+113# .
 #s   $B Bc                     U R                  5         U R                  5         [        U R                  S5      nUR	                  UR                  5       5        UR                  5         g)zWrite Credentials to file.

Args:
    credentials: Credentials, the credentials to store.

Raises:
    CredentialsFileSymbolicLinkError if the file is a symbolic link.
wN)r:   r$   r(   r   writeto_jsonr*   )r   r0   r1   s      r   
locked_putStorage.locked_putU   sJ     	##%%	##%&		r   c                 D    [         R                  " U R                  5        g)zXDelete Credentials file.

Args:
    credentials: Credentials, the credentials to store.
N)r   unlinkr   r#   s    r   locked_deleteStorage.locked_deleted   s     			$..!r   )r   )r   r	   r
   r   r   r   r$   r3   r:   r@   rD   r   __classcell__)r   s   @r   r   r   "   s*    D"H
4$" "r   r   )	r   r   r   oauth2clientr   
__author__	Exceptionr   r   r   r   r   <module>rJ      s:    
   4
8y 8H"fnn H"r   