
    h+                         S r SSKJr  SS/rSSKrSSKJr  SSKJr  SSKJ	r	  SS	K
Jr   " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  SS jr\rSS jr\rS r\rS r\rg)zDThe User Python datastore class to be used as a datastore data type.    )absolute_importz!jonmac@google.com (Jon McAlister)zryanb@google.com (Ryan Barrett)N)
six_subset)apiproxy_stub_map)user_service_pb)apiproxy_errorsc                       \ rS rSrSrSrg)Error$   zBase User error type. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       )lib/googlecloudsdk/appengine/api/users.pyr	   r	   $   s    r   r	   c                       \ rS rSrSrSrg)UserNotFoundError(   z:No email argument was specified, and no user is logged in.r   Nr   r   r   r   r   r   (   s    Br   r   c                       \ rS rSrSrSrg)RedirectTooLongError,   z(The generated redirect URL was too long.r   Nr   r   r   r   r   r   ,   s    0r   r   c                       \ rS rSrSrSrg)NotAllowedError0   z*The requested redirect URL is not allowed.r   Nr   r   r   r   r   r   0   s    2r   r   c                   v    \ rS rSrSrSrSrSr   SS jrS r	S r
S rS rS	 rS
 rS rS rS rS rS rSrg)User4   a  Provides the email address, nickname, and ID for a user.

A nickname is a human-readable string that uniquely identifies a Google user,
akin to a username. For some users, this nickname is an email address, but for
other users, a different nickname is used.

A user is a Google Accounts user.

`federated_identity` and `federated_provider` are decommissioned and should
not be used.
Nc                    Uc  [         R                  R                  S5      nU(       d   eUc  Uc  [         R                  R                  SU5      n[         R                  R                  SU5      n[         R                  R                  SU5      n[         R                  R                  SU5      nUc  SnU(       d  U(       d  U(       a  [        eXl        X@l        XPl        X l        U=(       d    SU l        g)a\  Constructor.

Args:
  email: An optional string of the user's email address. It defaults to
      the current user's email address.
  federated_identity: Decommissioned, don't use.
  federated_provider: Decommissioned, don't use.

Raises:
  UserNotFoundError: If the user is not logged in and both `email` and
      `federated_identity` are empty.
NAUTH_DOMAIN
USER_EMAILUSER_IDFEDERATED_IDENTITYFEDERATED_PROVIDER )	osenvirongetr   _User__email_User__federated_identity_User__federated_provider_User__auth_domain_User__user_id)selfemail_auth_domain_user_idfederated_identityfederated_provider_strict_modes          r   __init__User.__init__I   s    , ZZ^^M2l<}+3jjnn\51e	84h::>>*>*<>::>>*>*<> }e+ L 2 2%%DNr   c                 B   U R                   (       af  U R                  (       aU  U R                   R                  SU R                  -   5      (       a(  [        U R                  5      S-   nU R                   SU*  $ U R                  (       a  U R                  $ U R                   $ )a  Returns the user's nickname.

The nickname will be a unique, human readable identifier for this user with
respect to this application. It will be an email address for some users,
and part of the email address for some users.

Returns:
  The nickname of the user as a string.
@   N)r+   r.   endswithlenr,   )r0   
suffix_lens     r   nicknameUser.nickname~   sz     	++cD$6$6677t))*Q.j\\,J;''		"	"&&&\\r   c                     U R                   $ )z!Returns the user's email address.)r+   r0   s    r   r1   
User.email   s    <<r   c                     U R                   $ )zObtains the user ID of the user.

Returns:
  A permanent unique identifying string or `None`. If the email address was
  set explicitly, this will return `None`.
)r/   rB   s    r   user_idUser.user_id   s     >>r   c                     U R                   $ )zObtains the user's authentication domain.

Returns:
  A string containing the authentication domain. This method is internal and
  should not be used by client applications.
)r.   rB   s    r   auth_domainUser.auth_domain   s     r   c                     U R                   $ )zDecommissioned, don't use.

Returns:
  A string containing the federated identity of the user. If the user is not
  a federated user, `None` is returned.
)r,   rB   s    r   r4   User.federated_identity        $$$r   c                     U R                   $ )zDecommissioned, don't use.

Returns:
  A string containing the federated provider. If the user is not a federated
  user, `None` is returned.
)r-   rB   s    r   r5   User.federated_provider   rL   r   c                 J    [         R                  " U R                  5       5      $ N)r   	text_typer?   rB   s    r   __unicode__User.__unicode__   s    00r   c                 4    [        U R                  5       5      $ rP   )strr?   rB   s    r   __str__User.__str__   s    t}}r   c                 H   / nU R                   (       a  UR                  SU R                   -  5        U R                  (       a  UR                  SU R                  -  5        U R                  (       a  UR                  SU R                  -  5        SSR	                  U5      -  $ )Nz
email='%s'zfederated_identity='%s'z_user_id='%s'zusers.User(%s),)r+   appendr,   r/   join)r0   valuess     r   __repr__User.__repr__   st    F||mmL4<</0  mm-0I0IIJ~~mmOdnn45chhv...r   c                     U R                   (       a!  [        U R                   U R                  45      $ [        U R                  U R                  45      $ rP   )r,   hashr.   r+   rB   s    r   __hash__User.__hash__   sA      4,,d.@.@ABB4<<!3!3455r   c                 :   [        U[        5      (       d  [        $ U R                  (       a8  [	        U R                  U R
                  4UR                  UR
                  45      $ [	        U R                  U R
                  4UR                  UR
                  45      $ rP   )
isinstancer   NotImplementedr,   cmpr.   r+   )r0   others     r   __cmp__User.__cmp__   s    eT""  $++T-?-?@,,e.A.ABD D $,, 2 23--!4!457 7r   )__auth_domain__email__federated_identity__federated_provider	__user_id)NNNNNT)r   r   r   r   r   r/   r,   r-   r7   r?   r1   rE   rH   r4   r5   rR   rV   r]   ra   rh   r   r   r   r   r   r   4   s`    
  ).2JN 2&j&%%1 /67r   r   c                 D   [         R                  " 5       n[         R                  " 5       nU (       a  UR                  U 5        OUR                  S5        U(       a  UR	                  U5        U(       a  [        S5      e [        R                  " SSX45        UR                  5       $ ! [        R                   ac  nUR                  [         R                  R                  :X  a  [        eUR                  [         R                  R                  :X  a  [
        eUeSnAff = f)a  Computes the login URL for redirection.

Args:
  dest_url: String that is the desired final destination URL for the user
      once login is complete. If `dest_url` does not specify a host, the host
      from the current request is used.
  federated_identity: Decommissioned, don't use. Setting this to a non-None
      value raises a NotAllowedError

Returns:
     Login URL as a string. The login URL will use Google Accounts.

Raises:
    NotAllowedError: If federated_identity is not None.
r'   z#OpenID 2.0 support is decomissioneduserCreateLoginURLN)r   CreateLoginURLRequestCreateLoginURLResponseset_destination_urlset_auth_domainr   r   MakeSyncCallr   ApplicationErrorapplication_errorUserServiceErrorREDIRECT_URL_TOO_LONGr   NOT_ALLOWED	login_url)dest_urlr2   r4   reqrespes         r   create_login_urlr      s    " 	--/#		/	/	1$H%B%
?
@@
""6+;SG 
	 
	)	) 	((>>	?  




*
*
6
67gs    B( (D<ADDc                    [         R                  " 5       n[         R                  " 5       nUR                  U 5        U(       a  UR	                  U5         [
        R                  " SSX#5        UR                  5       $ ! [        R                   a5  nUR                  [         R                  R                  :X  a  [        eUeSnAff = f)ap  Computes the logout URL and specified destination URL for the request.

This function works for Google Accounts applications.

Args:
  dest_url: String that is the desired final destination URL for the user
      after the user has logged out. If `dest_url` does not specify a host,
      the host from the current request is used.

Returns:
  Logout URL as a string.
rp   CreateLogoutURLN)r   CreateLogoutURLRequestCreateLogoutURLResponsert   ru   r   rv   r   rw   rx   ry   rz   r   
logout_url)r}   r2   r~   r   r   s        r   create_logout_urlr   
  s     	..0#		0	0	2$(#%""6+<cH 
	 
	)	) 	((>>	?  gs   A= =C0CCc                  8     [        5       $ ! [         a     gf = f)zTRetrieves information associated with the user that is making a request.

Returns:

N)r   r   r   r   r   get_current_userr   +  s     6M	 s   	 
c                  H    [         R                  R                  SS5      S:H  $ )a  Specifies whether the user making a request is an application admin.

Because administrator status is not persisted in the datastore,
`is_current_user_admin()` is a separate function rather than a member function
of the `User` class. The status only exists for the user making the current
request.

Returns:
  `True` if the user is an administrator; all other user types return `False`.
USER_IS_ADMIN01)r(   r)   r*   r   r   r   is_current_user_adminr   :  s     **..#
.3	66r   )NNNrP   )r   
__future__r   
__author__r(   "googlecloudsdk.appengine._internalr   googlecloudsdk.appengine.apir   r    googlecloudsdk.appengine.runtimer   	Exceptionr	   r   r   r   objectr   r   rq   r   r   r   GetCurrentUserr   IsCurrentUserAdminr   r   r   <module>r      s    K '1/1

 
 9 : 8 <I C C15 13e 3c76 c7L 26(,'T "< $	 "7 + r   