
                             S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  Sr " S S\	5      r
 " S S	\
5      r " S
 S\
5      rSr " S S\5      rS r " S S\R"                  5      rg)z;OAuth 2.0 utitilies for Google Developer Shell environment.    N)_helpers)clientDEVSHELL_CLIENT_PORTc                       \ rS rSrSrSrg)Error   zErrors for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r	       0lib/third_party/oauth2client/contrib/devshell.pyr   r      s    !r   r   c                       \ rS rSrSrSrg)CommunicationError!   z9Errors for communication with the Developer Shell server.r	   Nr
   r	   r   r   r   r   !   s    Cr   r   c                       \ rS rSrSrSrg)NoDevshellServer%   z6Error when no Developer Shell server can be contacted.r	   Nr
   r	   r   r   r   r   %   s    @r   r   z[]c                       \ rS rSrSrS rSrg)CredentialInfoResponse.   a  Credential information response from Developer Shell server.

The credential information response from Developer Shell socket is a
PBLite-formatted JSON array with fields encoded by their index in the
array:

* Index 0 - user email
* Index 1 - default project ID. None if the project context is not known.
* Index 2 - OAuth2 access token. None if there is no valid auth context.
* Index 3 - Seconds until the access token expires. None if not present.
c                 :   [         R                  " U5      n[        U[        5      (       d  [	        S[        U5      -   5      e[        U5      nUS:  a  US   OSU l        US:  a  US   OSU l        US:  a  US   OSU l	        US:  a  US   U l
        gSU l
        g)z4Initialize the response data from JSON PBLite array.zNot a list: r   N         )jsonloads
isinstancelist
ValueErrorstrlen
user_email
project_idaccess_token
expires_in)selfjson_stringpblpbl_lens       r   __init__CredentialInfoResponse.__init__;   s    jj%#t$$^c#h677c($+aK#a&T$+aK#a&T&-kCFt$+aK#a&Tr   )r)   r*   r(   r'   N)r   r   r   r   r   r/   r   r	   r   r   r   r   .   s    
	:r   r   c                  |   [        [        R                  " [        S5      5      n U S:X  a
  [	        5       e[
        R
                  " 5       nUR                  SU 45        [        nSR                  [        U5      U5      nUR                  [        R                  " USS95        UR                  S5      R                  5       nSU;  a  [        S5      eUR!                  SS	5      u  pV[        U5      [        U5      -
  nUS:  a0  XaR                  U[
        R"                  5      R                  5       -  n[%        U5      $ )
z3Communicate with the Developer Shell server socket.r   	localhostz{0}
{1}zutf-8)encoding   
z#saw no newline in the first 6 bytesr   )intosgetenvDEVSHELL_ENVr   socketconnectCREDENTIAL_INFO_REQUEST_JSONformatr&   sendallr   	_to_bytesrecvdecoder   splitMSG_WAITALLr   )portsockdatamsgheaderlen_strjson_strto_reads           r   	_SendRecvrL   G   s     ryyq)*Dqy  ==?DLL+t$%'D


CIt
,CLL##C':;YYq\  "F6 !FGGT1-G'lS]*G{IIgv'9'9:AACC!(++r   c                   v   ^  \ rS rSrSrS
U 4S jjrS r\S 5       r\S 5       r	\
S 5       r\S 5       rS	rU =r$ )DevshellCredentials`   a  Credentials object for Google Developer Shell environment.

This object will allow a Google Developer Shell session to identify its
user to Google and other OAuth 2.0 servers that can verify assertions. It
can be used for the purpose of accessing data stored under the user
account.

This credential does not require a flow to instantiate because it
represents a two legged flow, and therefore has all of the required
information to generate and refresh its own access tokens.
c           	      Z   > [         [        U ]  S S S S S S U5        U R                  S 5        g N)superrN   r/   _refresh)r+   
user_agent	__class__s     r   r/   DevshellCredentials.__init__m   s6    !41	 	dr   c                     [        5       U l        U R                  R                  U l        U R                  R                  nUb2  [        R
                  " US9n[        R                  " 5       U-   U l        g S U l        g )N)seconds)	rL   devshell_responser)   r*   datetime	timedeltar   _UTCNOWtoken_expiry)r+   http_requestr*   deltas       r   rS   DevshellCredentials._refreshx   sc    !* 22??++66
!&&z:E & 05 8D $Dr   c                 .    U R                   R                  $ rQ   )rY   r'   r+   s    r   r'   DevshellCredentials.user_email       %%000r   c                 .    U R                   R                  $ rQ   )rY   r(   rb   s    r   r(   DevshellCredentials.project_id   rd   r   c                     [        S5      e)Nz2Cannot load Developer Shell credentials from JSON.NotImplementedError)cls	json_datas     r   	from_jsonDevshellCredentials.from_json   s    !@B 	Br   c                     [        S5      e)Nz-Cannot serialize Developer Shell credentials.rh   rb   s    r   serialization_data&DevshellCredentials.serialization_data   s    !;= 	=r   )r)   rY   r]   rQ   )r   r   r   r   r   r/   rS   propertyr'   r(   classmethodrl   ro   r   __classcell__)rU   s   @r   rN   rN   `   sd    
	% 1 1 1 1 B B = =r   rN   )r   rZ   r    r7   r:   oauth2clientr   r   r9   	Exceptionr   r   r   r<   objectr   rL   GoogleCredentialsrN   r	   r   r   <module>rx      su    B   	  ! %	I 	
D DAu A  $ :V :2,22=&22 2=r   