a
    ù!fþ  ã                   @   s&   d Z ddlmZ G dd„ dejƒZdS )zGContains a storage module that stores credentials using the Django ORM.é    )Úclientc                       s8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
ÚDjangoORMStoragezÃStore and retrieve a single credential to and from the Django datastore.

    This Storage helper presumes the Credentials
    have been stored as a CredentialsField
    on a db model class.
    c                    s*   t t| ƒ ¡  || _|| _|| _|| _dS )aœ  Constructor for Storage.

        Args:
            model: string, fully qualified name of db.Model model class.
            key_name: string, key name for the entity that has the credentials
            key_value: string, key value for the entity that has the
               credentials.
            property_name: string, name of the property that is an
                           CredentialsProperty.
        N)Úsuperr   Ú__init__Úmodel_classÚkey_nameÚ	key_valueÚproperty_name)Úselfr   r   r   r	   ©Ú	__class__© úi/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/contrib/django_util/storage.pyr      s
    zDjangoORMStorage.__init__c                 C   sb   | j | ji}| jjjf i |¤Ž}t|ƒdkrZt|d | jƒ}t|ddƒdurV| | ¡ |S dS dS )aª  Retrieve stored credential from the Django ORM.

        Returns:
            oauth2client.Credentials retrieved from the Django ORM, associated
             with the ``model``, ``key_value``->``key_name`` pair used to query
             for the model, and ``property_name`` identifying the
             ``CredentialsProperty`` field, all of which are defined in the
             constructor for this Storage object.

        r   Ú	set_storeN)	r   r   r   ÚobjectsÚfilterÚlenÚgetattrr	   r   )r
   ÚqueryÚentitiesZ
credentialr   r   r   Ú
locked_get-   s    
zDjangoORMStorage.locked_getc                 C   s:   | j jjf i | j| ji¤Ž\}}t|| j|ƒ | ¡  dS )z„Write a Credentials to the Django datastore.

        Args:
            credentials: Credentials, the credentials to store.
        N)r   r   Zget_or_creater   r   Úsetattrr	   Úsave)r
   ÚcredentialsÚentityÚ_r   r   r   Ú
locked_putB   s
    
ÿ
zDjangoORMStorage.locked_putc                 C   s(   | j | ji}| jjjf i |¤Ž ¡  dS )z&Delete Credentials from the datastore.N)r   r   r   r   r   Údelete)r
   r   r   r   r   Úlocked_deleteN   s    zDjangoORMStorage.locked_delete)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Ú__classcell__r   r   r   r   r      s
   r   N)r"   Zoauth2clientr   ZStorager   r   r   r   r   Ú<module>   s   