
                         (   S r SSKrSSKJr  SSKJr  \R                  r \R                  r	 \R                  " \5      r " S S\R                  5      r " S S\R                  5      r " S	 S
\R                   5      r " S S\R                  5      rg)zGoogle 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                   J    \ rS rSrSr\R                  " 5       r\S 5       r	Sr
g)SiteXsrfSecretKeyNDB&   aF  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                     g)$Return the kind name for this class.SiteXsrfSecretKey clss    6lib/third_party/oauth2client/contrib/_appengine_ndb.py	_get_kindSiteXsrfSecretKeyNDB._get_kind2   s     #    r   N)__name__
__module____qualname____firstlineno____doc__r   StringPropertysecretclassmethodr   __static_attributes__r   r   r   r   r   &   s)     !F# #r   r   c                       \ rS rSrSrS rSrg)FlowNDBProperty8   aR  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                     [         R                  S[        U5      5        UbE  [        U[        R
                  5      (       d%  [        SR                  U R                  U5      5      egg)zValidates 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   Flow	TypeErrorformat_nameselfvalues     r   	_validateFlowNDBProperty._validateD   sZ     	,d5k:Zv{{%C%C++16$**e+DF F &Dr   r   N)r   r   r   r   r   r+   r   r   r   r   r   r   8   s    	Fr   r   c                   *    \ rS rSrSrS rS rS rSrg)CredentialsNDBPropertyT   aj  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                     [         R                  S[        U5      5        UbE  [        U[        R
                  5      (       d%  [        SR                  U R                  U5      5      egg)zValidates 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(   s     r   r+    CredentialsNDBProperty._validate`   s\     	,d5k:Zv7I7I%J%J++16$**e+DF F &Kr   c                 *    Uc  gUR                  5       $ )zConverts 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.
 )to_jsonr(   s     r   _to_base_type$CredentialsNDBProperty._to_base_typeo   s     ===?"r   c                 |    U(       d  g [         R                  R                  U5      nU$ ! [         a    Sn U$ f = f)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   r1   new_from_json
ValueError)r)   r*   credentialss      r   _from_base_type&CredentialsNDBProperty._from_base_type~   sI     	 ,,::5AK   	K	s   + ;;r   N)	r   r   r   r   r   r+   r6   r<   r   r   r   r   r.   r.   T   s    	F#r   r.   c                   6    \ rS rSrSr\" 5       r\S 5       rSr	g)CredentialsNDBModel   a  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                     g)r	   CredentialsModelr   r   s    r   r   CredentialsNDBModel._get_kind   s     "r   r   N)
r   r   r   r   r   r.   r;   r   r   r   r   r   r   r?   r?      s#    	 )*K" "r   r?   )r   logginggoogle.appengine.extr   oauth2clientr   KeyNDB_KEYModel	NDB_MODEL	getLoggerr   r    r   PicklePropertyr   BlobPropertyr.   r?   r   r   r   <module>rN      s     $  '' AII	 C


H
%#399 #$Fc(( F8<S-- <~"#)) "r   