
    	                     b    d Z ddlZddlZddlmZ ddlmZ ddlZ G d dej                        Z	y)z1Contains classes used for the Django ORM storage.    N)models)encodingc                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )CredentialsFieldz0Django ORM field for storing OAuth2 Credentials.c                 >    d|vrd|d<   t        t        | 
  |i | y )NnullT)superr   __init__)selfargskwargs	__class__s      :lib/third_party/oauth2client/contrib/django_util/models.pyr
   zCredentialsField.__init__   s)    !F6N.??    c                      y)NBinaryField )r   s    r   get_internal_typez"CredentialsField.get_internal_type"   s    r   c                 $    | j                  |      S )zOverrides ``models.Field`` method. This converts the value
        returned from the database to an instance of this class.
        )	to_python)r   value
expression
connectioncontexts        r   from_db_valuezCredentialsField.from_db_value%   s     ~~e$$r   c                     |yt        |t        j                  j                        r|S t	        j
                  t        j                  t        j                  |                  S )z~Overrides ``models.Field`` method. This is used to convert
        bytes (from serialization etc) to an instance of this classN)

isinstanceoauth2clientclientCredentialspickleloadsbase64	b64decoder   smart_bytesr   r   s     r   r   zCredentialsField.to_python+   sL     =|22>>?L<< 0 01E1Ee1L MNNr   c                 ~    |yt        j                  t        j                  t	        j
                  |                  S )zOverrides ``models.Field`` method. This is used to convert
        the value from an instances of this class to bytes that can be
        inserted into the database.
        N)r   
smart_textr#   	b64encoder!   dumpsr&   s     r   get_prep_valuezCredentialsField.get_prep_value5   s1    
 =&&v'7'7U8K'LMMr   c                 F    | j                  |      }| j                  |      S )zConvert the field value from the provided model to a string.

        Used during model serialization.

        Args:
            obj: db.Model, model object

        Returns:
            string, the serialized field value
        )_get_val_from_objr+   )r   objr   s      r   value_to_stringz CredentialsField.value_to_string?   s%     &&s+""5))r   )__name__
__module____qualname____doc__r
   r   r   r   r+   r/   __classcell__)r   s   @r   r   r      s'    :@
%ON*r   r   )
r3   r#   r!   	django.dbr   django.utilsr   r   Fieldr   r   r   r   <module>r8      s)    8    ! 1*v|| 1*r   