Ë
    v»•jI  ã                   óH  — d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ ddlm	Z ddlmZ  ej                   e«      ZdZ G d	„ d
ej(                  «      Z G d„ dej(                  «      Z G d„ dej.                  «      Z G d„ dej0                  «      Zy)z–Transport 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                   óX   — e Zd ZdZd„ Zd„ Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d„ Zy	)
Ú_CombinedResponsea@  
    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                 ó    — || _         d | _        y ©N)Ú	_responseÚ_raw_content©ÚselfÚresponses     úZ/var/www/html/venv/lib/python3.12/site-packages/google/auth/transport/_aiohttp_requests.pyÚ__init__z_CombinedResponse.__init__:   s   € Ø!ˆŒØ ˆÕó    c                 ó^   — | j                   j                  }d|v xr |d   dk(  xs |d   dk(  S )NúContent-EncodingÚgzipÚdeflate©r   Úheaders)r   r   s     r   Ú_is_compressedz _CombinedResponse._is_compressed>   sD   € Ø—.‘.×(Ñ(ˆØ! WÐ,ò 
ØÐ&Ñ'¨6Ñ1ò 8ØÐ)Ñ*¨iÑ7ð	
r   c                 ó.   — | j                   j                  S r   ©r   Ústatus©r   s    r   r   z_CombinedResponse.statusE   ó   € à�~‰~×$Ñ$Ð$r   c                 ó.   — | j                   j                  S r   r   r   s    r   r   z_CombinedResponse.headersI   ó   € à�~‰~×%Ñ%Ð%r   c                 ó.   — | j                   j                  S r   ©r   Úcontentr   s    r   Údataz_CombinedResponse.dataM   r"   r   c              ƒ   ó    K  — | j                   €1| j                  j                  j                  «       ƒ d {  –—† | _         | j                   S 7 Œ­wr   )r   r   r%   Úreadr   s    r   Úraw_contentz_CombinedResponse.raw_contentQ   sB   è ø€ Ø×ÑÐ$Ø&*§n¡n×&<Ñ&<×&AÑ&AÓ&C× CˆDÔØ× Ñ Ð ð !Dús   ‚4A¶A·Ac              ƒ   ó  K  — | j                  «       ƒ d {  –—†  | j                  «       rSt        j                  j	                  | j
                  j                  d   «      }|j                  | j                  «      }|S | j                  S 7 Œs­w)Nr   )	r)   r   Úurllib3r   ÚMultiDecoderr   r   Ú
decompressr   )r   ÚdecoderÚdecompresseds      r   r%   z_CombinedResponse.contentV   s|   è ø€ à×ÑÓ × Ð Ø×ÑÔ Ü×&Ñ&×3Ñ3Ø—‘×&Ñ&Ð'9Ñ:óˆGð #×-Ñ-¨d×.?Ñ.?Ó@ˆLØÐà× Ñ Ð ð 	!ús   ‚B–B
—A4BN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r   r&   r)   r%   © r   r   r
   r
   -   sW   „ ñ
ò!ò
ð ñ%ó ð%ð ñ&ó ð&ð ñ&ó ð&ò!ó

!r   r
   c                   óF   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zy)Ú	_Responsezz
    Requests transport response adapter.

    Args:
        response (requests.Response): The raw Requests response.
    c                 ó   — || _         y r   )r   r   s     r   r   z_Response.__init__k   s	   € Ø!ˆ�r   c                 ó.   — | j                   j                  S r   r   r   s    r   r   z_Response.statusn   r    r   c                 ó.   — | j                   j                  S r   r   r   s    r   r   z_Response.headersr   r"   r   c                 ó.   — | j                   j                  S r   r$   r   s    r   r&   z_Response.datav   r"   r   N)	r0   r1   r2   r3   r   r4   r   r   r&   r5   r   r   r7   r7   c   sH   „ ñò"ð ñ%ó ð%ð ñ&ó ð&ð ñ&ó ñ&r   r7   c                   ó4   — e Zd ZdZdd„Zdddefd„Zd„ Zd„ Zy)	ÚRequestaÚ  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                 ól   — |�$t        |dd «      du rt        j                  d«      ‚|| _        d| _        y )NÚauto_decompressTz<Client sessions with auto_decompress=True are not supported.F)Úgetattrr   ÚInvalidOperationÚsessionÚ_closed)r   rB   s     r   r   zRequest.__init__’   s@   € ØÐ¤7¨7Ð4EÀtÓ#LÐPTÑ#TÜ×-Ñ-ØNóð ð ˆŒØˆ�r   ÚGETc              ‹   óP  K  — 	 t        | dd«      rt        j                  d«      ‚| j                  €t	        j
                  d¬«      | _        t        j                  t        ||||«        | j                  j                  ||f|||dœ|¤Žƒ d{  –—† }t        j                  t        |«      ƒ d{  –—†  t        |«      S 7 Œ17 Œ# t        j                  $ r}t        j                  |«      }	|	|‚d}~wt        j                  $ r}t        j                  |«      }	|	|‚d}~ww xY w­w)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.
        rC   Fzsession is closed.N)r?   ©r&   r   Útimeout)r@   r   ÚTransportErrorrB   ÚaiohttpÚClientSessionr   Úrequest_logÚ_LOGGERÚrequestÚ_helpers_asyncÚresponse_log_asyncr
   ÚClientErrorÚasyncioÚTimeoutError)
r   ÚurlÚmethodÚbodyr   rG   Úkwargsr   Ú
caught_excÚnew_excs
             r   Ú__call__zRequest.__call__š   s  è ø€ ðB	*Ü�t˜Y¨Ô.Ü ×/Ñ/Ð0DÓEÐEà�|‰|Ð#Ü&×4Ñ4Ø$)ô �”ô × Ñ ¤¨&°#°t¸WÔEØ1˜TŸ\™\×1Ñ1Ø˜ðØ"&°ÀñØLRñ÷ ˆHô !×3Ñ3´G¸XÓF×FÐFÜ$ XÓ.Ð.ð	øð Gùô ×"Ñ"ò 	*Ü ×/Ñ/°
Ó;ˆGØ˜zÐ)ûä×#Ñ#ò 	*Ü ×/Ñ/°
Ó;ˆGØ˜zÐ)ûð	*üsY   ‚D&„BC ÂCÂ!C Â1CÂ2C Ã D&ÃC ÃC ÃD#ÃC0Ã0D#ÄDÄD#Ä#D&c           
      ó  — t        | dd«      rt        j                  d«      ‚| j                  s#t	        j
                  dd¬«      }t        |¬«      S dt        | j                  dd«      dœ}t        | j                  dd	«      }|�rt        |d
d«      �st        |t        j                  «      r]t	        j                  t        |dd	«      t        |dd«      t        |dd«      t        |dd«      t        j                  |«      ¬«      |d<   n�t        t        dd	«      r[t        |t        t        d«      «      rAt        |dd	«      }|rSt	        j                  |t        |dd«      t        |dd«      ¬«      |d<   n!t        j                  dt        |«      › �«      ‚t        | j                  dd	«      }|rt        |«      |d<   dD ]$  \  }}t        | j                  |d	«      }|€Œ |||<   Œ& t        t	        j
                  di |¤Ž¬«      S )a�  Creates an independent copy of this request adapter.

        Clones the connection settings, trace configurations, and session defaults
        (headers, cookies, basic auth, and timeouts).

        Only standard `aiohttp.TCPConnector` and `aiohttp.UnixConnector` connectors
        are supported. The DNS resolver is not copied to avoid closing shared resolver
        resources.

        Returns:
            google.auth.transport._aiohttp_requests.Request: A new request adapter.

        Raises:
            google.auth.exceptions.TransportError: If the transport is closed, or if the
                session uses an unsupported connector.
        rC   Fz Cannot clone a closed transport.T©r?   Ú	trust_env)rB   Ú
_trust_envÚ
_connectorNÚclosedÚ_sslÚ_limitéd   Ú_limit_per_hostr   Ú_force_close)ÚsslÚlimitÚlimit_per_hostÚforce_closeÚ
local_addrÚ	connectorÚUnixConnectorÚ_path)Úpathrf   rh   z(Unsupported connector type for cloning: Ú_trace_configsÚtrace_configs))Ú_default_headersr   )Ú_cookie_jarÚ
cookie_jar)Ú_default_authÚauth)Ú_timeoutrG   )Ú_json_serializeÚjson_serializer5   )r@   r   rH   rB   rI   rJ   r=   Ú
isinstanceÚTCPConnectorrN   Ú_get_local_addrrk   ÚtypeÚlist)	r   Únew_sessionÚsession_kwargsÚorig_connectorrm   ro   Ú	attr_nameÚ
kwarg_nameÚvals	            r   Ú_clonezRequest._cloneÒ   sô  € ô" �4˜ EÔ*Ü×+Ñ+Ð,NÓOÐOà�|Š|Ü!×/Ñ/Ø %ØôˆKô  ;Ô/Ð/ð  %Ü  §¡¨|¸TÓBñ 
ˆô ! §¡¨|¸TÓBˆÚ¤'¨.¸(ÀDÕ"IÜ˜.¬'×*>Ñ*>Ô?ô /6×.BÑ.BÜ °¸Ó=Ü! .°(¸CÓ@Ü#*¨>Ð;LÈaÓ#PÜ '¨¸ÈÓ NÜ-×=Ñ=¸nÓMô/�˜{Ò+ô œ /°4Ô8¼ZØ¤¬°Ó Aô>ô ˜~¨w¸Ó=�ÙÜ29×2GÑ2GØ!Ü% n°hÀÓDÜ$+¨N¸NÈEÓ$Rô3�N ;Ò/ô !×/Ñ/Ø>¼tÀNÓ?SÐ>TÐUóð ô
   §¡Ð.>ÀÓEˆÙÜ.2°=Ó.AˆN˜?Ñ+ð&
ò 		1Ñ!ˆI�zô ˜$Ÿ,™,¨	°4Ó8ˆCØ‰Ø-0�˜zÒ*ð		1ô œw×4Ñ4ÑF°~ÑFÔGÐGr   c              ƒ   ó”   K  — t        | dd«      s.| j                  r"| j                  j                  «       ƒ d{  –—†  d| _        y7 Œ­w)z?Cleanly release the underlying aiohttp ClientSession resources.rC   FNT)r@   rB   ÚcloserC   r   s    r   r…   zRequest.close"  s:   è ø€ ä�t˜Y¨Ô.°4·<²<Ø—,‘,×$Ñ$Ó&×&Ð&Øˆ�ð 'ús   ‚7A¹AºAr   )	r0   r1   r2   r3   r   Ú_DEFAULT_TIMEOUTrY   rƒ   r…   r5   r   r   r=   r=   {   s-   „ ñó,ð ØØØ ó6*òpNHó`r   r=   c                   ól   ‡ — e Zd ZdZej
                  ej                  dddfˆ fd„	Zdddedfˆ fd„	Z	ˆ xZ
S )ÚAuthorizedSessionaN  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                 ó   •— t        t        | �
  di |¤Ž || _        || _        || _        || _        d| _        || _        d | _	        t        j                  «       | _        t        j                  «       | _        || _        y )NFr5   )Úsuperrˆ   r   ÚcredentialsÚ_refresh_status_codesÚ_max_refresh_attemptsÚ_refresh_timeoutÚ_is_mtlsÚ_auth_requestÚ_auth_request_sessionrQ   Úget_event_loopÚ_loopÚLockÚ_refresh_lockÚ_auto_decompress)	r   r‹   Úrefresh_status_codesÚmax_refresh_attemptsÚrefresh_timeoutÚauth_requestr?   rV   Ú	__class__s	           €r   r   zAuthorizedSession.__init__P  su   ø€ ô 	Ô Ñ/Ñ9°&Ò9Ø&ˆÔØ%9ˆÔ"Ø%9ˆÔ"Ø /ˆÔØˆŒØ)ˆÔØ%)ˆÔ"Ü×+Ñ+Ó-ˆŒ
Ü$Ÿ\™\›^ˆÔØ /ˆÕr   c           
   ‹   óü  •K  — |rA|j                  «       D ].  }	t        ||	   «      t        u sŒ||	   j                  d«      ||	<   Œ0 t	        j
                  | j                  |j                  dd«      ¬«      4 ƒd{  –—† | _        t        | j                  «      }
|
| _
        |j                  dd«      }|�|j                  «       ni }|€| j                  n t        j                  | j                  |¬«      }
|}t        j                   |t"        j$                  «      5 }| j&                  j)                  |
|||«      ƒ d{  –—†  ddd«       t        j                   |t"        j$                  «      5 }t+        t,        | �^  ||f|||d	œ|¤Žƒ d{  –—† }ddd«       j0                  }j2                  | j4                  v �rE|| j6                  k  �r5t        j8                  j;                  d
|j2                  |dz   | j6                  «       |€| j                  n t        j                  | j                  |¬«      }
t        j                   |t"        j$                  «      5 }| j<                  4 ƒd{  –—†  | j>                  jA                  d| j&                  jB                  |
«      ƒ d{  –—†  ddd«      ƒd{  –—†  ddd«       |j0                  } | j.                  ||f|||||dz   dœ|¤Žƒ d{  –—† cddd«      ƒd{  –—†  S ddd«      ƒd{  –—†  |S 7 �Œš7 �ŒÚ# 1 sw Y   �ŒÚxY w7 �Œœ# 1 sw Y   �ŒœxY w7 ŒÌ7 Œ•7 Œ‡# 1 ƒd{  –—†7  sw Y   Œ—xY w# 1 sw Y   Œ›xY w7 Œq7 Œc7 ŒT# 1 ƒd{  –—†7  sw Y   S xY w­w)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 timeout error will be raised after such
                request completes.
        zutf-8r\   Fr[   NÚ_credential_refresh_attemptr   )rG   rF   z;Refreshing credentials due to a %s response. Attempt %s/%s.é   )r&   r   Úmax_allowed_timerG   r�   )"Úkeysr{   ÚbytesÚdecoderI   rJ   r–   Úgetr‘   r=   r�   ÚpopÚcopyÚ	functoolsÚpartialr   ÚTimeoutGuardrQ   rR   r‹   Úbefore_requestrŠ   rˆ   rM   Úremaining_timeoutr   rŒ   r�   rL   Úinfor•   r“   Úrun_in_executorÚrefresh)r   rT   rS   r&   r   rŸ   rG   r?   rV   Úkeyrš   r�   Úrequest_headersÚremaining_timeÚguardr   r›   s                   €r   rM   zAuthorizedSession.requestf  s›  øè ø€ ñT Ø—|‘|“~ò @�Ü˜ ™Ó%¬Ò.Ø#*¨3¡<×#6Ñ#6°wÓ#?�G˜C’Lð@ô ×(Ñ(Ø ×1Ñ1Ø—j‘j ¨eÓ4ô
÷ O	ð O	ð Ô'Ü" 4×#=Ñ#=Ó>ˆLØ!-ˆDÔð +1¯*©*Ð5RÐTUÓ*VÐ'ð 18Ð0C˜gŸl™lœnÈˆOð �?ð ×"Ò"ä×&Ñ& t×'9Ñ'9À7ÔKð ð .ˆNä×&Ñ& ~´w×7KÑ7KÓLð ÐPUØ×&Ñ&×5Ñ5Ø  &¨#¨ó÷ ð ÷ô
 ×&Ñ& ~´w×7KÑ7KÓLð ÐPUÜ!&Ô'8¸$Ñ!GØØð"ð Ø+Ø#ñ"ð ñ"÷ �÷ð #×4Ñ4ˆNð —‘ 4×#=Ñ#=Ò=Ø/°$×2LÑ2LÓLä× Ñ ×%Ñ%ØQØ—O‘OØ/°!Ñ3Ø×.Ñ.ô	ð �ð ×&Ò&ä"×*Ñ*¨4×+=Ñ+=ÀwÔOð ô ×*Ñ*Ø"¤G×$8Ñ$8óð àØ#×1Ñ1÷ ñ Ø"Ÿj™j×8Ñ8Ø  $×"2Ñ"2×":Ñ":¸Ló÷ ð ÷÷ ÷ð "'×!8Ñ!8�à)˜TŸ\™\ØØð	ð Ø#Ø%3Ø#Ø0KÈaÑ0Oñ	ð ñ	÷ 	÷MO	÷ O	÷ O	÷ O	ñ O	ðb ˆðcO	ùð2ù÷ñ úðù÷ñ úðDøðøðø÷ ÷ ñ ú÷ð úð	øðMO	øð O	ø÷ O	÷ O	ð O	ðb ˆüs3  ƒ*M<®AM<Á<LÁ=M<Â BM&Ä"LÄ?LÅ LÅ,M&Å0L,ÆL)ÆL,ÆC	M&ÉMÉ,L9
É-MÉ05L?Ê%L;
Ê&L?Ê*MÊ5L=Ê6MÊ:4M&Ë.M Ë/M&Ë2M<Ë>M"Ë?M<ÌM$ÌM<ÌLÌL&	Ì!M&Ì)L,Ì,L6	Ì1M&Ì9MÌ;L?Ì=MÌ?MÍMÍMÍMÍM	ÍM&Í"M<Í$M<Í&M9Í,M/Í-M9Í4M<)r0   r1   r2   r3   r   ÚDEFAULT_REFRESH_STATUS_CODESÚDEFAULT_MAX_REFRESH_ATTEMPTSr   r†   rM   Ú__classcell__)r›   s   @r   rˆ   rˆ   )  sH   ø„ ñ$ðR '×CÑCØ&×CÑCØØØõ0ð4 ØØØ Ø÷@ñ @r   rˆ   )r3   Ú
__future__r   rQ   r¦   ÚloggingrI   r+   Úgoogle.authr   r   r   Úgoogle.auth.aiorN   Úgoogle.auth.transportr   Ú	getLoggerr0   rL   r†   ÚResponser
   r7   r=   rJ   rˆ   r5   r   r   ú<module>r¼      s—   ðñõ 'ã Û Û ã Û å  Ý "Ý !Ý 6Ý *ð ˆ'×
Ñ
˜HÓ
%€ð
 Ð ô3!˜	×*Ñ*ô 3!ôl&�	×"Ñ"ô &ô0kˆi×Ñô kô\}˜×-Ñ-õ }r   