a
    !f                     @   s6   d Z ddlZddlZddlmZ G dd dejZdS )zRA keyring based Storage.

A Storage for Credentials that uses the keyring module.
    N)clientc                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
StorageaM  Store and retrieve a single credential to and from the keyring.

    To use this module you must have the keyring module installed. See
    <http://pypi.python.org/pypi/keyring/>. This is an optional module and is
    not installed with oauth2client by default because it does not work on all
    the platforms that oauth2client supports, such as Google App Engine.

    The keyring module <http://pypi.python.org/pypi/keyring/> is a
    cross-platform library for access the keyring capabilities of the local
    system. The user will be prompted for their keyring password when this
    module is used, and the manner in which the user is prompted will vary per
    platform.

    Usage::

        from oauth2client import keyring_storage

        s = keyring_storage.Storage('name_of_application', 'user1')
        credentials = s.get()

    c                    s&   t t| jt d || _|| _dS )zConstructor.

        Args:
            service_name: string, The name of the service under which the
                          credentials are stored.
            user_name: string, The name of the user to store credentials for.
        )lockN)superr   __init__	threadingLock_service_name
_user_name)selfservice_nameZ	user_name	__class__ e/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/contrib/keyring_storage.pyr   2   s    zStorage.__init__c                 C   sN   d}t | j| j}|durJztj|}||  W n tyH   Y n0 |S )zeRetrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        N)	keyringget_passwordr	   r
   r   CredentialsZnew_from_jsonZ	set_store
ValueError)r   credentialscontentr   r   r   
locked_get>   s    zStorage.locked_getc                 C   s   t | j| j|  dS )zrWrite Credentials to file.

        Args:
            credentials: Credentials, the credentials to store.
        N)r   set_passwordr	   r
   to_json)r   r   r   r   r   
locked_putP   s    zStorage.locked_putc                 C   s   t | j| jd dS )zpDelete Credentials file.

        Args:
            credentials: Credentials, the credentials to store.
         N)r   r   r	   r
   )r   r   r   r   locked_deleteY   s    zStorage.locked_delete)	__name__
__module____qualname____doc__r   r   r   r   __classcell__r   r   r   r   r      s
   	r   )r    r   r   Zoauth2clientr   r   r   r   r   r   <module>   s   