
                         >    S r SSKJr   " S S\R                  5      rg)zGContains a storage module that stores credentials using the Django ORM.    )clientc                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )DjangoORMStorage   zStore 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                 Z   > [         [        U ]  5         Xl        X l        X0l        X@l        g)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__s        ;lib/third_party/oauth2client/contrib/django_util/storage.pyr	   DjangoORMStorage.__init__   s)     	.0& "*    c                    U R                   U R                  0nU R                  R                  R                  " S0 UD6n[        U5      S:  a:  [        US   U R                  5      n[        USS5      b  UR                  U 5        U$ g)ar  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entities
credentials       r   
locked_getDjangoORMStorage.locked_get-   s}     /##++22;U;x=1 !d.@.@AJz;5A$$T*r   c                     U R                   R                  R                  " S0 U R                  U R                  0D6u  p#[        X R                  U5        UR                  5         g)zlWrite a Credentials to the Django datastore.

Args:
    credentials: Credentials, the credentials to store.
Nr   )r
   r   get_or_creater   r   setattrr   save)r   credentialsentity_s       r   
locked_putDjangoORMStorage.locked_putB   sR     $$,,:: /}}dnn-/	 	**K8r   c                     U R                   U R                  0nU R                  R                  R                  " S0 UD6R                  5         g)z&Delete Credentials from the datastore.Nr   )r   r   r
   r   r   delete)r   r   s     r   locked_deleteDjangoORMStorage.locked_deleteN   s:    /  ''0%0779r   )r   r   r
   r   )__name__
__module____qualname____firstlineno____doc__r	   r   r&   r*   __static_attributes____classcell__)r   s   @r   r   r      s!    +"*
: :r   r   N)r0   oauth2clientr   Storager   r   r   r   <module>r5      s    N =:v~~ =:r   