
    NBh9                     H   S r SSKJr  SSK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SKJr  SSKJ	r  SSKJr  \R                   " \5      rSr " S	 S
\R(                  5      r " S S\R(                  5      r " S S\R.                  5      r " S S\R0                  5      rg)zTransport adapter for Async HTTP (aiohttp).

NOTE: This async support is experimental and marked internal. This surface may
change in minor releases.
    )absolute_importN)_helpers)
exceptions)	transport)requests   c                   `    \ rS rSrSrS rS r\S 5       r\S 5       r	\S 5       r
S rS	 rS
rg)_CombinedResponse,   a  
In order to more closely resemble the `requests` interface, where a raw
and deflated content could be accessed at once, this class lazily reads the
stream in `transport.Response` so both return forms can be used.

The gzip and deflate transfer-encodings are automatically decoded for you
because the default parameter for autodecompress into the ClientSession is set
to False, and therefore we add this class to act as a wrapper for a user to be
able to access both the raw and decoded response bodies - mirroring the sync
implementation.
c                     Xl         S U l        g N)	_response_raw_contentselfresponses     lC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\google/auth/transport/_aiohttp_requests.py__init___CombinedResponse.__init__9   s    !     c                 t    U R                   R                  nSU;   =(       a    US   S:H  =(       d    US   S:H  $ )NContent-Encodinggzipdeflater   headers)r   r   s     r   _is_compressed _CombinedResponse._is_compressed=   sD    ..((!W, 
&'61 8)*i7	
r   c                 .    U R                   R                  $ r   r   statusr   s    r   r!   _CombinedResponse.statusD       ~~$$$r   c                 .    U R                   R                  $ r   r   r"   s    r   r   _CombinedResponse.headersH       ~~%%%r   c                 .    U R                   R                  $ r   r   contentr"   s    r   data_CombinedResponse.dataL   r'   r   c                    #    U R                   c1  U R                  R                  R                  5       I S h  vN U l         U R                   $  N7fr   )r   r   r*   readr"   s    r   raw_content_CombinedResponse.raw_contentP   sA     $&*nn&<&<&A&A&C CD    !Ds   5AAAc                 &  #    U R                  5       I S h  vN   U R                  5       (       aS  [        R                  R	                  U R
                  R                  S   5      nUR                  U R                  5      nU$ U R                  $  Nx7f)Nr   )	r/   r   urllib3r   MultiDecoderr   r   
decompressr   )r   decoderdecompresseds      r   r*   _CombinedResponse.contentU   s~          &&33&&'9:G #--d.?.?@L    	!s   BBA9B)r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   propertyr!   r   r+   r/   r*   __static_attributes__ r   r   r
   r
   ,   sW    
!
 % % & & & &!

!r   r
   c                   N    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	Sr
g)		_Responseb   zj
Requests transport response adapter.

Args:
    response (requests.Response): The raw Requests response.
c                     Xl         g r   r   r   s     r   r   _Response.__init__j   s    !r   c                 .    U R                   R                  $ r   r    r"   s    r   r!   _Response.statusm   r$   r   c                 .    U R                   R                  $ r   r   r"   s    r   r   _Response.headersq   r'   r   c                 .    U R                   R                  $ r   r)   r"   s    r   r+   _Response.datau   r'   r   rD   N)r8   r9   r:   r;   r<   r   r=   r!   r   r+   r>   r?   r   r   rA   rA   b   sH    " % % & & & &r   rA   c                   4    \ rS rSrSrSS jrSSS\4S jrSrg)	Requestz   a  Requests request adapter.

This class is used internally for making requests using asyncio transports
in a consistent way. If you use :class:`AuthorizedSession` you do not need
to construct or use this class directly.

This class can be useful if you want to manually refresh a
:class:`~google.auth.credentials.Credentials` instance::

    import google.auth.transport.aiohttp_requests

    request = google.auth.transport.aiohttp_requests.Request()

    credentials.refresh(request)

Args:
    session (aiohttp.ClientSession): An instance :class:`aiohttp.ClientSession` used
        to make HTTP requests. If not specified, a session will be created.

.. automethod:: __call__
Nc                 d    Ub'  UR                   (       a  [        R                  " S5      eXl        g )Nz<Client sessions with auto_decompress=True are not supported.)_auto_decompressr   InvalidOperationsession)r   rR   s     r   r   Request.__init__   s-    7#;#;--N  r   GETc                 
  #     U R                   c  [        R                  " SS9U l         [        R                  " [
        X!X45        U R                   R                  " X!4X4US.UD6I Sh  vN n[        R                  " [
        U5      I Sh  vN   [        U5      $  N2 N! [        R                   a  n[        R                  " U5      n	XeSnAf[        R                   a  n[        R                  " U5      n	XeSnAff = f7f)a  
Make an HTTP request using aiohttp.

Args:
    url (str): The URL to be requested.
    method (Optional[str]):
        The HTTP method to use for the request. Defaults to 'GET'.
    body (Optional[bytes]):
        The payload or body in HTTP request.
    headers (Optional[Mapping[str, str]]):
        Request headers.
    timeout (Optional[int]): The number of seconds to wait for a
        response from the server. If not specified or if None, the
        requests default timeout will be used.
    kwargs: Additional arguments passed through to the underlying
        requests :meth:`requests.Session.request` method.

Returns:
    google.auth.transport.Response: The HTTP response.

Raises:
    google.auth.exceptions.TransportError: If any exception occurred.
NF)auto_decompressr+   r   timeout)rR   aiohttpClientSessionr   request_log_LOGGERrequest_helpers_asyncresponse_log_asyncr
   ClientErrorr   TransportErrorasyncioTimeoutError)
r   urlmethodbodyr   rX   kwargsr   
caught_excnew_excs
             r   __call__Request.__call__   s     B	*||#&44$)    &tE!\\11"&LR H !33GXFFF$X..	 G "" 	* //
;G)## 	* //
;G)	*sY   DA%B  )B*"B  BB  DB  B   D 4CD #C;;D  D)rR   r   )	r8   r9   r:   r;   r<   r   _DEFAULT_TIMEOUTrj   r>   r?   r   r   rM   rM   z   s    ,  3*r   rM   c                   |   ^  \ rS rSrSr\R                  \R                  SSS4U 4S jjrSSS\	S4U 4S jjr
SrU =r$ )AuthorizedSession   a  This is an async implementation of the Authorized Session class. We utilize an
aiohttp transport instance, and the interface mirrors the google.auth.transport.requests
Authorized Session class, except for the change in the transport used in the async use case.

A Requests Session class with credentials.

This class is used to perform requests to API endpoints that require
authorization::

    from google.auth.transport import aiohttp_requests

    async with aiohttp_requests.AuthorizedSession(credentials) as authed_session:
        response = await authed_session.request(
            'GET', 'https://www.googleapis.com/storage/v1/b')

The underlying :meth:`request` implementation handles adding the
credentials' headers to the request and refreshing credentials as needed.

Args:
    credentials (google.auth._credentials_async.Credentials):
        The credentials to add to the request.
    refresh_status_codes (Sequence[int]): Which HTTP status codes indicate
        that credentials should be refreshed and the request should be
        retried.
    max_refresh_attempts (int): The maximum number of times to attempt to
        refresh the credentials and retry the request.
    refresh_timeout (Optional[int]): The timeout value in seconds for
        credential refresh HTTP requests.
    auth_request (google.auth.transport.aiohttp_requests.Request):
        (Optional) An instance of
        :class:`~google.auth.transport.aiohttp_requests.Request` used when
        refreshing credentials. If not passed,
        an instance of :class:`~google.auth.transport.aiohttp_requests.Request`
        is created.
    kwargs: Additional arguments passed through to the underlying
        ClientSession :meth:`aiohttp.ClientSession` object.
NFc                    > [         [        U ]
  " S0 UD6  Xl        X l        X0l        X@l        SU l        XPl        S U l	        [        R                  " 5       U l        [        R                  " 5       U l        X`l        g )NFr?   )superrn   r   credentials_refresh_status_codes_max_refresh_attempts_refresh_timeout_is_mtls_auth_request_auth_request_sessionrb   get_event_loop_loopLock_refresh_lockrP   )	r   rr   refresh_status_codesmax_refresh_attemptsrefresh_timeoutauth_requestrV   rg   	__class__s	           r   r   AuthorizedSession.__init__   si     	/9&9&%9"%9" /)%)"++-
$\\^ /r   c           
      :  >#    U(       aB  UR                  5        H.  n	[        XI   5      [        L d  M  XI   R                  S5      XI'   M0     [        R
                  " U R                  UR                  SS5      S9 ISh  vN U l        [        U R                  5      n
Xl
        UR                  SS5      nUb  UR                  5       O0 nUc  U R                  O[        R                  " U R                  US9n
Un[        R                   " U["        R$                  5       nU R&                  R)                  XX,5      I Sh  vN   SSS5        [        R                   " U["        R$                  5       n[*        [,        U ]^  " UU4UUUS	.UD6I Sh  vN nSSS5        WR0                  nWR2                  U R4                  ;   GaE  XR6                  :  Ga5  [        R8                  R;                  S
UR2                  US-   U R6                  5        Uc  U R                  O[        R                  " U R                  US9n
[        R                   " U["        R$                  5       nU R<                   ISh  vN   U R>                  RA                  SU R&                  RB                  U
5      I Sh  vN   SSS5      ISh  vN   SSS5        UR0                  nU R.                  " UU4UUUUUS-   S.UD6I Sh  vN sSSS5      ISh  vN   $ SSS5      ISh  vN   U$  GN GN! , (       d  f       GN= f GN! , (       d  f       GN= f N N N! , ISh  vN  (       d  f       N= f! , (       d  f       N= f N Nw Nh! , ISh  vN  (       d  f       W$ = f7f)a*  Implementation of Authorized Session aiohttp request.

Args:
    method (str):
        The http request method used (e.g. GET, PUT, DELETE)
    url (str):
        The url at which the http request is sent.
    data (Optional[dict]): Dictionary, list of tuples, bytes, or file-like
        object to send in the body of the Request.
    headers (Optional[dict]): Dictionary of HTTP Headers to send with the
        Request.
    timeout (Optional[Union[float, aiohttp.ClientTimeout]]):
        The amount of time in seconds to wait for the server response
        with each individual request. Can also be passed as an
        ``aiohttp.ClientTimeout`` object.
    max_allowed_time (Optional[float]):
        If the method runs longer than this, a ``Timeout`` exception is
        automatically raised. Unlike the ``timeout`` parameter, this
        value applies to the total method execution time, even if
        multiple requests are made under the hood.

        Mind that it is not guaranteed that the timeout error is raised
        at ``max_allowed_time``. It might take longer, for example, if
        an underlying request takes a lot of time, but the request
        itself does not timeout, e.g. if a large file is being
        transmitted. The timout error will be raised after such
        request completes.
zutf-8	trust_envF)rV   r   N_credential_refresh_attemptr   )rX   rW   z;Refreshing credentials due to a %s response. Attempt %s/%s.   )r+   r   max_allowed_timerX   r   )"keystypebytesdecoderY   rZ   rP   getrx   rM   rw   popcopy	functoolspartialr   TimeoutGuardrb   rc   rr   before_requestrq   rn   r]   remaining_timeoutr!   rs   rt   r\   infor|   rz   run_in_executorrefresh)r   re   rd   r+   r   r   rX   rV   rg   keyr   r   request_headersremaining_timeguardr   r   s                   r   r]   AuthorizedSession.request  sG    V ||~%.#*<#6#6w#?GL & (( 11jje4
 
 '"4#=#=>L!- +1**5RTU*V' 180CgllnO ? ""&&t'9'97K  .N&&~w7K7KLPU&&55 #   M
 &&~w7K7KLPU!&'8$!G" +#" "  M #44N 4#=#==/2L2LL   %%QOO/!3..	  &&"**4+=+=wO  **"G$8$8#111"jj88 $"2"2":":L    21 "'!8!8!\\	 #%3#0Ka0O	 	 	O
 
 
 
 
d e
2 ML MLF  2  2111 	O
 
 
 
d s3  -NAN LNBN ! L"LL"-N 3L7L4L7CN !M)2M	
3M)65M+M
,M0M);M<M) 4N 4M:5N 8NM<NM>NL""
L1	,N 4L77
M	N 	M)MM)M&MM&"M))
M7	3N <N>N NN	NN)
rw   rx   rP   rv   rz   rt   r|   rs   ru   rr   )r8   r9   r:   r;   r<   r   DEFAULT_REFRESH_STATUS_CODESDEFAULT_MAX_REFRESH_ATTEMPTSr   rl   r]   r>   __classcell__)r   s   @r   rn   rn      sH    $R 'CC&CC04  B Br   rn   )r<   
__future__r   rb   r   loggingrY   r2   google.authr   r   r   google.auth.aior^   google.auth.transportr   	getLoggerr8   r\   rl   Responser
   rA   rM   rZ   rn   r?   r   r   <module>r      s    '        " ! 6 * 

H
%  3!	** 3!l&	"" &0R*i R*j-- r   