a
    ù!fª
  ã                   @   sB   d Z ddlZddlZddlmZ ddlmZ G dd„ dejƒZdS )zYUtilities for OAuth.

Utilities for making it easier to work with OAuth 2.0
credentials.
é    N)Ú_helpers)Úclientc                       s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )ÚStoragez:Store and retrieve a single credential to and from a file.c                    s    t t| ƒjt ¡ d || _d S )N)Úlock)Úsuperr   Ú__init__Ú	threadingÚLockÚ	_filename)ÚselfÚfilename©Ú	__class__© úR/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/file.pyr      s    zStorage.__init__c                 C   sz   d}t  | j¡ z t| jdƒ}| ¡ }| ¡  W n tyF   | Y S 0 ztj 	|¡}| 
| ¡ W n tyt   Y n0 |S )zªRetrieve Credential from file.

        Returns:
            oauth2client.client.Credentials

        Raises:
            IOError if the file is a symbolic link.
        NÚrb)r   Úvalidate_filer
   ÚopenÚreadÚcloseÚIOErrorr   ÚCredentialsZnew_from_jsonZ	set_storeÚ
ValueError)r   ÚcredentialsÚfÚcontentr   r   r   Ú
locked_get#   s    	
zStorage.locked_getc              	   C   sH   t j | j¡sDt  d¡}zt| jdƒ ¡  W t  |¡ nt  |¡ 0 dS )z½Create 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   Z	old_umaskr   r   r   Ú_create_file_if_needed=   s
    
zStorage._create_file_if_neededc                 C   s:   |   ¡  t | j¡ t| jdƒ}| | ¡ ¡ | ¡  dS )z·Write 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   r   r   r   Ú
locked_putJ   s
    	zStorage.locked_putc                 C   s   t  | j¡ dS )zpDelete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
        N)r   Úunlinkr
   )r   r   r   r   Úlocked_deleteY   s    zStorage.locked_delete)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r&   r(   Ú__classcell__r   r   r   r   r      s   r   )r,   r   r   Zoauth2clientr   r   r   r   r   r   r   Ú<module>   s
   