a
    ù!f  ã                   @   s†   d Z ddlZddlmZ ddlmZ ejZejZ	e 
e¡ZG dd„ dejƒZG dd„ dejƒZG d	d
„ d
ejƒZG dd„ dejƒZdS )zÊGoogle App Engine utilities helper.

Classes that directly require App Engine's ndb library. Provided
as a separate module in case of failure to import ndb while
other App Engine libraries are present.
é    N)Úndb)Úclientc                   @   s$   e Zd ZdZe ¡ Zedd„ ƒZdS )ÚSiteXsrfSecretKeyNDBa^  NDB Model for storage for the sites XSRF secret key.

    Since this model uses the same kind as SiteXsrfSecretKey, it can be
    used interchangeably. This simply provides an NDB model for interacting
    with the same data the DB model interacts with.

    There should only be one instance stored of this model, the one used
    for the site.
    c                 C   s   dS )ú$Return the kind name for this class.ZSiteXsrfSecretKey© ©Úclsr   r   úd/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/contrib/_appengine_ndb.pyÚ	_get_kind2   s    zSiteXsrfSecretKeyNDB._get_kindN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZStringPropertyÚsecretÚclassmethodr
   r   r   r   r	   r   &   s   	r   c                   @   s   e Zd ZdZdd„ ZdS )ÚFlowNDBPropertyan  App Engine NDB datastore Property for Flow.

    Serves the same purpose as the DB FlowProperty, but for NDB models.
    Since PickleProperty inherits from BlobProperty, the underlying
    representation of the data in the datastore will be the same as in the
    DB case.

    Utility property that allows easy storage and retrieval of an
    oauth2client.Flow
    c                 C   s:   t  dt|ƒ¡ |dur6t|tjƒs6td | j|¡ƒ‚dS )zÈValidates a value as a proper Flow object.

        Args:
            value: A value to be set on the property.

        Raises:
            TypeError if the value is not an instance of Flow.
        úvalidate: Got type %sNzCProperty {0} must be convertible to a flow instance; received: {1}.)	Ú_LOGGERÚinfoÚtypeÚ
isinstancer   ZFlowÚ	TypeErrorÚformatÚ_name©ÚselfÚvaluer   r   r	   Ú	_validateD   s    	ÿÿzFlowNDBProperty._validateN)r   r   r   r   r   r   r   r   r	   r   8   s   r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCredentialsNDBPropertya†  App Engine NDB datastore Property for Credentials.

    Serves the same purpose as the DB CredentialsProperty, but for NDB
    models. Since CredentialsProperty stores data as a blob and this
    inherits from BlobProperty, the data in the datastore will be the same
    as in the DB case.

    Utility property that allows easy storage and retrieval of Credentials
    and subclasses.
    c                 C   s:   t  dt|ƒ¡ |dur6t|tjƒs6td | j|¡ƒ‚dS )zÖValidates a value as a proper credentials object.

        Args:
            value: A value to be set on the property.

        Raises:
            TypeError if the value is not an instance of Credentials.
        r   NzJProperty {0} must be convertible to a credentials instance; received: {1}.)	r   r   r   r   r   ÚCredentialsr   r   r   r   r   r   r	   r   `   s    	ÿÿz CredentialsNDBProperty._validatec                 C   s   |du rdS |  ¡ S dS )zùConverts our validated value to a JSON serialized string.

        Args:
            value: A value to be set in the datastore.

        Returns:
            A JSON serialized version of the credential, else '' if value
            is None.
        NÚ )Úto_jsonr   r   r   r	   Ú_to_base_typeo   s    
z$CredentialsNDBProperty._to_base_typec                 C   s4   |sdS zt j |¡}W n ty.   d}Y n0 |S )a:  Converts our stored JSON string back to the desired type.

        Args:
            value: A value from the datastore to be converted to the
                   desired type.

        Returns:
            A deserialized Credentials (or subclass) object, else None if
            the value can't be parsed.
        N)r   r   Znew_from_jsonÚ
ValueError)r   r   Úcredentialsr   r   r	   Ú_from_base_type~   s    
z&CredentialsNDBProperty._from_base_typeN)r   r   r   r   r   r"   r%   r   r   r   r	   r   T   s   r   c                   @   s"   e Zd ZdZeƒ Zedd„ ƒZdS )ÚCredentialsNDBModelaÑ  NDB Model for storage of OAuth 2.0 Credentials

    Since this model uses the same kind as CredentialsModel and has a
    property which can serialize and deserialize Credentials correctly, it
    can be used interchangeably with a CredentialsModel to access, insert
    and delete the same entities. This simply provides an NDB model for
    interacting with the same data the DB model interacts with.

    Storage of the model is keyed by the user.user_id().
    c                 C   s   dS )r   ZCredentialsModelr   r   r   r   r	   r
       s    zCredentialsNDBModel._get_kindN)r   r   r   r   r   r$   r   r
   r   r   r   r	   r&   “   s   
r&   )r   ÚloggingZgoogle.appengine.extr   Zoauth2clientr   ÚKeyZNDB_KEYZModelZ	NDB_MODELÚ	getLoggerr   r   r   ZPicklePropertyr   ZBlobPropertyr   r&   r   r   r   r	   Ú<module>   s   
?