
    h
                     X    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dS )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                               || _        d S )N)lock)superr   __init__	threadingLock	_filename)selffilename	__class__s     i/home/visionen/pythonvenv/lib/python3.11/site-packages/oauth2client-4.1.3-py3.11.egg/oauth2client/file.pyr
   zStorage.__init__   s7    gt%%9>+;+;%<<<!    c                 j   d}t          j        | j                   	 t          | j        d          }|                                }|                                 n# t          $ r |cY S w xY w	 t          j        	                    |          }|
                    |            n# t          $ r Y nw xY w|S )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contents       r   
locked_getzStorage.locked_get#   s     t~...	T^T**AffhhGGGIIII 	 	 			 ,::7CCK!!$'''' 	 	 	D	 s#   =A A*)A*.4B# #
B0/B0c                 $   t           j                            | j                  skt          j        d          }	 t          | j        d                                           t          j        |           dS # t          j        |           w xY 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_umasks     r   _create_file_if_neededzStorage._create_file_if_needed=   s     w~~dn-- 	$I$T^U++11333#########	$ 	$s   'A7 7Bc                     |                                   t          j        | 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   s      r   
locked_putzStorage.locked_putJ   si     	##%%%t~...%%	##%%&&&						r   c                 8    t          j        | j                   dS )zpDelete Credentials file.

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