o
    i
                     @   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__ L/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/oauth2client/file.pyr      s   
zStorage.__init__c                 C   sz   d}t | j zt| jd}| }|  W n ty#   | Y S w ztj	|}|
|  W |S  ty<   Y |S w )zRetrieve 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   Credentialsnew_from_json	set_store
ValueError)r   credentialsfcontentr   r   r   
locked_get#   s"   	zStorage.locked_getc              	   C   sJ   t j| js#t d}zt| jd  W t | dS t | w dS )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_umaskr   r   r   _create_file_if_needed=   s   
zStorage._create_file_if_neededc                 C   s:   |    t| j t| jd}||  |  dS )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   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   oauth2clientr   r   r   r   r   r   r   <module>   s   