Ë
    ¹ÿju‡  ã                   ó4  — d Z ddlmZ ddlZddlZddl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mZ ddlmZ 	 ddlZddlZddlZddlmZ ddlZddlmZmZmZ ddlm Z  dd	l!m"Z"  e	jF                  e$«      Z%d
Z& G d„ dejN                  «      Z( G d„ de)«      Z*d„ Z+ G d„ dejX                  «      Z, G d„ dejZ                  j\                  «      Z/ G d„ dejZ                  j\                  «      Z0 G d„ dejb                  «      Z2y# e$ rZ ed«      e‚dZ[ww xY w)zTransport adapter for Requests.é    )Úabsolute_importN)ÚOptionalzmThe requests library is not installed from please install the requests package to use the requests transport.)Úcreate_urllib3_context)Ú_helpersÚ
exceptionsÚ	transport)Ú_mtls_helper)Úservice_accountéx   c                   óF   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zy)Ú	_ResponsezuRequests transport response adapter.

    Args:
        response (requests.Response): The raw Requests response.
    c                 ó   — || _         y ©N)Ú	_response)ÚselfÚresponses     úX/root/telegram-saas/.venv/lib/python3.12/site-packages/google/auth/transport/requests.pyÚ__init__z_Response.__init__;   s	   € Ø!ˆ�ó    c                 ó.   — | j                   j                  S r   )r   Ústatus_code©r   s    r   Ústatusz_Response.status>   s   € à�~‰~×)Ñ)Ð)r   c                 ó.   — | j                   j                  S r   )r   Úheadersr   s    r   r   z_Response.headersB   ó   € à�~‰~×%Ñ%Ð%r   c                 ó.   — | j                   j                  S r   )r   Úcontentr   s    r   Údataz_Response.dataF   r   r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   © r   r   r   r   4   sH   „ ñò"ð ñ*ó ð*ð ñ&ó ð&ð ñ&ó ñ&r   r   c                   óN   — e Zd ZdZej
                  j                  fd„Zd„ Zd„ Z	y)ÚTimeoutGuardaU  A context manager raising an error if the suite execution took too long.

    Args:
        timeout (Union[None, Union[float, Tuple[float, float]]]):
            The maximum number of seconds a suite can run without the context
            manager raising a timeout exception on exit. If passed as a tuple,
            the smaller of the values is taken as a timeout. If ``None``, a
            timeout error is never raised.
        timeout_error_type (Optional[Exception]):
            The type of the error to raise on timeout. Defaults to
            :class:`requests.exceptions.Timeout`.
    c                 ó.   — || _         || _        || _        y r   )Ú_timeoutÚremaining_timeoutÚ_timeout_error_type)r   ÚtimeoutÚtimeout_error_types      r   r   zTimeoutGuard.__init__Y   s   € ØˆŒØ!(ˆÔØ#5ˆÕ r   c                 ó8   — t        j                   «       | _        | S r   )ÚtimeÚ_startr   s    r   Ú	__enter__zTimeoutGuard.__enter__^   s   € Ü—i‘i“kˆŒØˆr   c                 ó–  ‡— |ry | j                   €y t        j                  «       | j                  z
  Šd}t        | j                   t        j
                  «      r$| j                   ‰z
  | _        | j                  dk  }n;t        ˆfd„| j                   D «       «      | _        t        | j                  «      dk  }|r| j                  «       ‚y )NFr   c              3   ó(   •K  — | ]	  }|‰z
  –— Œ y ­wr   r%   )Ú.0ÚxÚelapseds     €r   ú	<genexpr>z(TimeoutGuard.__exit__.<locals>.<genexpr>p   s   øè ø€ Ò*N¸1¨1¨w­;Ñ*Nùs   ƒ)
r)   r/   r0   Ú
isinstanceÚnumbersÚNumberr*   ÚtupleÚminr+   )r   Úexc_typeÚ	exc_valueÚ	tracebackÚdeadline_hitr6   s        @r   Ú__exit__zTimeoutGuard.__exit__b   s¥   ø€ ÙØà�=‰=Ð Øä—)‘)“+ §¡Ñ+ˆØˆä�d—m‘m¤W§^¡^Ô4Ø%)§]¡]°WÑ%<ˆDÔ"Ø×1Ñ1°QÑ6‰Lä%*Ó*NÀÇÁÔ*NÓ%NˆDÔ"Ü˜t×5Ñ5Ó6¸!Ñ;ˆLáØ×*Ñ*Ó,Ð,ð r   N)
r    r!   r"   r#   Úrequestsr   ÚTimeoutr   r1   rA   r%   r   r   r'   r'   K   s'   „ ñð 4<×3FÑ3F×3NÑ3Nó 6ò
ó-r   r'   c                 ó¬   — | j                   j                  «       }|||<   t        j                  t	        |j                  «       d„ d¬«      «      | _         y)a  Mounts an adapter on a session without mutating its adapters in place.

    ``adapter`` is mounted on ``session`` for ``prefix``.
    :meth:`requests.Session.mount` mutates the ``session.adapters``
    OrderedDict in place. If another thread is iterating over it in
    :meth:`requests.Session.get_adapter` at the same time, that thread fails
    with ``RuntimeError: OrderedDict mutated during iteration``. This builds
    an updated copy and assigns it in one step instead, so threads that are
    already iterating over the old dictionary are not affected.

    Args:
        session (requests.Session): The session to mount the adapter on.
        prefix (str): The URL prefix to mount the adapter for.
        adapter (requests.adapters.BaseAdapter): The adapter to mount.
    c                 ó   — t        | d   «      S )Nr   )Úlen)Úitems    r   ú<lambda>z"_replace_adapter.<locals>.<lambda>Œ   s   € ´c¸$¸q¹'³l€ r   T)ÚkeyÚreverseN)ÚadaptersÚcopyÚcollectionsÚOrderedDictÚsortedÚitems)ÚsessionÚprefixÚadapterÚnew_adapterss       r   Ú_replace_adapterrU   w   sM   € ð  ×#Ñ#×(Ñ(Ó*€LØ"€L�Ñô #×.Ñ.Üˆ|×!Ñ!Ó#Ñ)BÈDÔQó€GÕr   c                   ól   — e Zd ZdZdZdZddeej                     ddfd„Z	d„ Z
d„ Zd	„ Zd
„ Zdddefd„Zy)ÚRequestaØ  Requests request adapter.

    This class is used internally for making requests using various 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.requests
        import requests

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

        credentials.refresh(request)

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

    .. automethod:: __call__
    NFrQ   Úreturnc                 óŒ   — |st        j                  «       }|| _        d | _        d| _        t        j                  «       | _        y )NF)rB   ÚSessionrQ   Ú_mtls_adapterÚ_mtls_unavailableÚ	threadingÚLockÚ
_mtls_lock)r   rQ   s     r   r   zRequest.__init__«   s8   € ÙÜ×&Ñ&Ó(ˆGàˆŒØ!ˆÔØ!&ˆÔÜ#Ÿ.™.Ó*ˆ�r   c                 óD   — | j                   j                  «       }d |d<   |S )Nr_   )Ú__dict__rL   ©r   Ústates     r   Ú__getstate__zRequest.__getstate__´   s#   € Ø—‘×"Ñ"Ó$ˆØ"ˆˆlÑØˆr   c                 ó°   — | j                   j                  |«       t        j                  «       | _        t        | j                  t        «      sd | _        y y r   )ra   Úupdater]   r^   r_   r8   r[   Ú_MutualTlsAdapterrb   s     r   Ú__setstate__zRequest.__setstate__¹   sA   € Ø�‰×Ñ˜UÔ#Ü#Ÿ.™.Ó*ˆŒÜ˜$×,Ñ,Ô.?Ô@Ø!%ˆDÕð Ar   c                 óŒ   — 	 t        | d«      r(| j                  �| j                  j                  «        y y y # t        $ r Y y w xY w)NrQ   )ÚhasattrrQ   ÚcloseÚ	TypeErrorr   s    r   Ú__del__zRequest.__del__¿   sG   € ð	Ü�t˜YÔ'¨D¯L©LÐ,DØ—‘×"Ñ"Õ$ð -EÐ'øäò 	ñ ð		ús   ‚27 ·	AÁAc           	      óZ  — t        j                  |«      syt        j                  |«      }|j                  › d|j
                  j                  «       › d�}| j                  5  | j                  j                  |j                  r|n|«      }t        |«      t        j                  j                  us| j                  j                  |«      |ur
	 ddd«       y| j                  €“| j                   st        j"                  «       s
	 ddd«       yt        j$                  «       \  }}}|sd| _        	 ddd«       yt'        |||j(                  |j*                  |j,                  |j.                  ¬«      | _        t1        | j                  || j                  «       ddd«       y# 1 sw Y   yxY w)zŽLazily mounts a mutual TLS adapter onto the session for mTLS endpoints.

        Args:
            url (str): The target request URL.
        Nz://ú/T)Úmax_retriesÚpool_connectionsÚpool_maxsizeÚ
pool_block)r	   Úis_mtls_endpointÚurllib_parseÚurlparseÚschemeÚnetlocÚlowerr_   rQ   Úget_adapterÚpathÚtyperB   rK   ÚHTTPAdapterr[   r\   Úcheck_use_client_certÚget_client_cert_and_keyrg   rp   Ú_pool_connectionsÚ_pool_maxsizeÚ_pool_blockrU   )r   ÚurlÚparsedrR   Úsession_adapterÚhas_certÚcertrI   s           r   Ú_configure_mtls_if_neededz!Request._configure_mtls_if_neededÉ   s{  € ô ×,Ñ,¨SÔ1Øô
 ×&Ñ& sÓ+ˆØ—M‘M�? # f§m¡m×&9Ñ&9Ó&;Ð%<¸AÐ>ˆØ�_‰_ñ 	GØ"Ÿl™l×6Ñ6¸f¿kºk±sÈvÓVˆOô �_Ó%¬X×->Ñ->×-JÑ-JÑJØ—<‘<×+Ñ+¨FÓ3¸?ÑJà÷	Gð 	Gð ×!Ñ!Ð)Ø×)Ò)´×1SÑ1SÔ1UØ÷	Gð 	Gô '3×&JÑ&JÓ&LÑ#�˜$ ÙØ-1�DÔ*Ø÷	Gð 	Gô" &7ØØØ /× ;Ñ ;Ø%4×%FÑ%FØ!0×!>Ñ!>Ø.×:Ñ:ô&�Ô"ô ˜TŸ\™\¨6°4×3EÑ3EÔF÷5	G÷ 	Gñ 	Gús    Á"A-F!Ã-F!Ä"F!Ä9AF!Æ!F*ÚGETc                 ó  — |j                  d«      s	 | j                  |«       	 t        j                  t        ||||«        | j                  j                  ||f|||dœ|¤Ž}	t        j                  t        |	«       t        |	«      S # t        j                  t        j                  t
        f$ r}t        j                  |«      }||‚d}~ww xY w# t        j                  j                  $ r}t        j                  |«      }||‚d}~ww xY w)aR  Make an HTTP request using requests.

        Args:
            url (str): The URI to be requested.
            method (str): The HTTP method to use for the request. Defaults
                to 'GET'.
            body (bytes): The payload or body in HTTP request.
            headers (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.
        r‡   N©r   r   r,   )Úgetrˆ   r   ÚMutualTLSChannelErrorÚClientCertErrorÚOSErrorÚTransportErrorr   Úrequest_logÚ_LOGGERrQ   ÚrequestÚresponse_logr   rB   ÚRequestException)
r   rƒ   ÚmethodÚbodyr   r,   ÚkwargsÚ
caught_excÚnew_excr   s
             r   Ú__call__zRequest.__call__ó   s  € ð: �z‰z˜&Ô!ð.Ø×.Ñ.¨sÔ3ð		*Ü× Ñ ¤¨&°#°t¸WÔEØ+�t—|‘|×+Ñ+Ø˜ðØ"&°ÀñØLRñˆHô ×!Ñ!¤'¨8Ô4Ü˜XÓ&Ð&øô ×0Ñ0Ü×*Ñ*Üðò .ô
 %×3Ñ3°JÓ?�Ø :Ð-ûð.ûô" ×"Ñ"×3Ñ3ò 	*Ü ×/Ñ/°
Ó;ˆGØ˜zÐ)ûð	*ús/   “B	 ¥A#C Â	(CÂ1C	Ã	CÃDÃ.DÄDr   )r    r!   r"   r#   r[   r\   r   rB   rZ   r   rd   rh   rm   rˆ   Ú_DEFAULT_TIMEOUTr›   r%   r   r   rW   rW   �   s[   „ ñð. €MØÐñ+ ¨×)9Ñ)9Ñ :ð +Àdó +òò
&òò(GðZ ØØØ ô3*r   rW   c                   óB   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ fd„Zˆ fd„Zˆ xZ	S )rg   a@  
    A TransportAdapter that enables mutual TLS.

    Args:
        cert (bytes): client certificate in PEM format
        key (bytes): client private key in PEM format

    Raises:
        ImportError: if certifi is not installed
        google.auth.exceptions.MutualTLSChannelError: If the cert or key is invalid.
    c                 ó^  •— dd l }dd l}t        «       }d|_        |j	                  |j                  «       ¬«       t        «       }d|_        |j	                  |j                  «       ¬«       	 t        j                  ||«      5 \  }}	}
|
}|j                  ||	|¬«       |j                  ||	|¬«       d d d «       || _        || _        t'        t(        | �V  di |¤Ž y # 1 sw Y   Œ+xY w# |j                  t        t        t        t        t        f$ r}t        j                   d«      |‚d }~ww xY w)Nr   F©Úcafile)ÚcertfileÚkeyfileÚpasswordz8Failed to configure client certificate and key for mTLS.r%   )ÚsslÚcertifir   Úcheck_hostnameÚload_verify_locationsÚwherer	   Úsecure_cert_key_pathsÚload_cert_chainÚSSLErrorr�   ÚIOErrorÚ
ValueErrorÚRuntimeErrorrl   r   r�   Ú_ctx_poolmanagerÚ_ctx_proxymanagerÚsuperrg   r   )r   r‡   rI   r˜   r¤   r¥   Úctx_poolmanagerÚctx_proxymanagerÚ	cert_pathÚkey_pathÚ
passphraser£   ÚexcÚ	__class__s                €r   r   z_MutualTlsAdapter.__init__6  s:  ø€ Ûãä0Ó2ˆØ).ˆÔ&Ø×-Ñ-°W·]±]³_Ð-ÔEä1Ó3ÐØ*/ÐÔ'Ø×.Ñ.°g·m±m³oÐ.ÔFð	Ü×3Ñ3°D¸#Ó>ð ñ CØØØà%�Ø×/Ñ/Ø&Ø$Ø%ð 0ô ð
 !×0Ñ0Ø&Ø$Ø%ð 1ô ÷ð8 !0ˆÔØ!1ˆÔäÔ Ñ/Ñ9°&Ó9÷?ð ûð" �L‰LÜÜÜÜÜð
ò 
	ô ×2Ñ2ØJóàðûð
	ús0   Á-C( Â/CÂ2C( ÃC%Ã!C( Ã()D,ÄD'Ä'D,c                 ó  — t         j                  t        | «      «      }||t        | «      <   | j                  |_        | j
                  |_        |j                  t        j                  | j                  «       |«      «       |S r   )
ÚobjectÚ__new__r|   Úidr¯   r°   rh   rL   Údeepcopyrd   )r   ÚmemoÚnew_adapters      r   Ú__deepcopy__z_MutualTlsAdapter.__deepcopy__e  se   € Ü—n‘n¤T¨$£ZÓ0ˆØ$ˆŒR�‹X‰Ø'+×'<Ñ'<ˆÔ$Ø(,×(>Ñ(>ˆÔ%Ø× Ñ ¤§¡¨t×/@Ñ/@Ó/BÀDÓ!IÔJØÐr   c                 óX   — t         j                  j                  d| j                  «       fS )Nr%   )rB   rK   r}   rd   )r   Úprotocols     r   Ú__reduce_ex__z_MutualTlsAdapter.__reduce_ex__m  s$   € Ü×!Ñ!×-Ñ-¨r°4×3DÑ3DÓ3FÐGÐGr   c                 óJ   •— | j                   |d<   t        t        | �  |i |¤Ž y ©NÚssl_context)r¯   r±   rg   Úinit_poolmanager©r   Úargsr˜   r¸   s      €r   rÇ   z"_MutualTlsAdapter.init_poolmanagerp  s(   ø€ Ø $× 5Ñ 5ˆˆ}ÑÜÔ Ñ7¸ÐHÀÓHr   c                 óH   •— | j                   |d<   t        t        | �  |i |¤ŽS rÅ   )r°   r±   rg   Úproxy_manager_forrÈ   s      €r   rË   z#_MutualTlsAdapter.proxy_manager_fort  s+   ø€ Ø $× 6Ñ 6ˆˆ}ÑÜÔ&¨Ñ?ÀÐPÈÑPÐPr   )
r    r!   r"   r#   r   rÀ   rÃ   rÇ   rË   Ú__classcell__©r¸   s   @r   rg   rg   )  s+   ø„ ñ
ô-:ò^òHôI÷Qð Qr   rg   c                   ó6   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zˆ fd„Zˆ xZS )Ú_MutualTlsOffloadAdaptera†  
    A TransportAdapter that enables mutual TLS and offloads the client side
    signing operation to the signing library.

    Args:
        enterprise_cert_file_path (str): the path to a enterprise cert JSON
            file. The file should contain the following field:

                {
                    "libs": {
                        "signer_library": "...",
                        "offload_library": "..."
                    }
                }

    Raises:
        ImportError: if certifi is not installed
        google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel
            creation failed for any reason.
    c                 óÎ  •— dd l }ddlm} |j                  |«      | _        | j                  j                  «        t        «       }|j                  |j                  «       ¬«       | j                  j                  |«       || _
        t        «       }|j                  |j                  «       ¬«       | j                  j                  |«       || _        t        t        | �;  «        y )Nr   )Ú_custom_tls_signerrŸ   )r¥   Úgoogle.auth.transportrÑ   ÚCustomTlsSignerÚsignerÚload_librariesr   r§   r¨   Úattach_to_ssl_contextr¯   r°   r±   rÏ   r   )r   Úenterprise_cert_file_pathr¥   rÑ   ÚpoolmanagerÚproxymanagerr¸   s         €r   r   z!_MutualTlsOffloadAdapter.__init__�  s¬   ø€ Ûå<à(×8Ñ8Ð9RÓSˆŒØ�‰×"Ñ"Ô$ä,Ó.ˆØ×)Ñ)°·±³Ð)ÔAØ�‰×)Ñ)¨+Ô6Ø +ˆÔä-Ó/ˆØ×*Ñ*°'·-±-³/Ð*ÔBØ�‰×)Ñ)¨,Ô7Ø!-ˆÔäÔ&¨Ñ6Õ8r   c                 óJ   •— | j                   |d<   t        t        | �  |i |¤Ž y rÅ   )r¯   r±   rÏ   rÇ   rÈ   s      €r   rÇ   z)_MutualTlsOffloadAdapter.init_poolmanager£  s(   ø€ Ø $× 5Ñ 5ˆˆ}ÑÜÔ&¨Ñ>ÀÐOÈÓOr   c                 óH   •— | j                   |d<   t        t        | �  |i |¤ŽS rÅ   )r°   r±   rÏ   rË   rÈ   s      €r   rË   z*_MutualTlsOffloadAdapter.proxy_manager_for§  s,   ø€ Ø $× 6Ñ 6ˆˆ}ÑÜÔ-¨tÑFÈÐWÐPVÑWÐWr   )r    r!   r"   r#   r   rÇ   rË   rÌ   rÍ   s   @r   rÏ   rÏ   y  s   ø„ ñô*9ô(P÷Xð Xr   rÏ   c                   ó’   ‡ — e Zd ZdZej
                  ej                  dddfˆ fd„	Zd	d„Zddde	fˆ fd„	Z
d„ Zed„ «       Zˆ fd„Zˆ xZS )
ÚAuthorizedSessiona"  A Requests Session class with credentials.

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

        from google.auth.transport.requests import AuthorizedSession

        authed_session = AuthorizedSession(credentials)

        response = 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.

    This class also supports mutual TLS via :meth:`configure_mtls_channel`
    method. In order to use this method, the `GOOGLE_API_USE_CLIENT_CERTIFICATE`
    environment variable must be explicitly set to ``true``, otherwise it does
    nothing. Assume the environment is set to ``true``, the method behaves in the
    following manner:

    If client_cert_callback is provided, client certificate and private
    key are loaded using the callback; if client_cert_callback is None,
    application default SSL credentials will be used. Exceptions are raised if
    there are problems with the certificate, private key, or the loading process,
    so it should be called within a try/except block.

    First we set the environment variable to ``true``, then create an :class:`AuthorizedSession`
    instance and specify the endpoints::

        regular_endpoint = 'https://pubsub.googleapis.com/v1/projects/{my_project_id}/topics'
        mtls_endpoint = 'https://pubsub.mtls.googleapis.com/v1/projects/{my_project_id}/topics'

        authed_session = AuthorizedSession(credentials)

    Now we can pass a callback to :meth:`configure_mtls_channel`::

        def my_cert_callback():
            # some code to load client cert bytes and private key bytes, both in
            # PEM format.
            some_code_to_load_client_cert_and_key()
            if loaded:
                return cert, key
            raise MyClientCertFailureException()

        # Always call configure_mtls_channel within a try/except block.
        try:
            authed_session.configure_mtls_channel(my_cert_callback)
        except:
            # handle exceptions.

        if authed_session.is_mtls:
            response = authed_session.request('GET', mtls_endpoint)
        else:
            response = authed_session.request('GET', regular_endpoint)


    You can alternatively use application default SSL credentials like this::

        try:
            authed_session.configure_mtls_channel()
        except:
            # handle exceptions.

    Args:
        credentials (google.auth.credentials.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.requests.Request):
            (Optional) An instance of
            :class:`~google.auth.transport.requests.Request` used when
            refreshing credentials. If not passed,
            an instance of :class:`~google.auth.transport.requests.Request`
            is created.
        default_host (Optional[str]): A host like "pubsub.googleapis.com".
            This is used when a self-signed JWT is created from service
            account credentials.
    Nc                 ót  •— t         t        | �  «        || _        || _        || _        || _        d| _        || _        t        j                  «       | _        |€kt        j                  «       | _        t        j                  j!                  d¬«      }| j                  j#                  d|«       t%        | j                  «      }nd | _        || _        t)        | j                  t*        j,                  «      rC| j                  j/                  | j                  rdj1                  | j                  «      nd «       y y )NFé   )rp   úhttps://zhttps://{}/)r±   rÝ   r   ÚcredentialsÚ_refresh_status_codesÚ_max_refresh_attemptsÚ_refresh_timeoutÚ_is_mtlsÚ_default_hostr]   r^   Ú_mtls_reauth_lockrB   rZ   Ú_auth_request_sessionrK   r}   ÚmountrW   Ú_auth_requestr8   r
   ÚCredentialsÚ_create_self_signed_jwtÚformat)	r   rá   Úrefresh_status_codesÚmax_refresh_attemptsÚrefresh_timeoutÚauth_requestÚdefault_hostÚretry_adapterr¸   s	           €r   r   zAuthorizedSession.__init__  s  ø€ ô 	Ô Ñ/Ô1Ø&ˆÔØ%9ˆÔ"Ø%9ˆÔ"Ø /ˆÔØˆŒØ)ˆÔÜ!*§¡Ó!1ˆÔàÐÜ)1×)9Ñ)9Ó);ˆDÔ&ô
 %×-Ñ-×9Ñ9ÀaÐ9ÓHˆMØ×&Ñ&×,Ñ,¨Z¸ÔGô # 4×#=Ñ#=Ó>‰Là)-ˆDÔ&ð *ˆÔô �d×&Ñ&¬×(CÑ(CÔDØ×Ñ×4Ñ4Ø<@×<NÒ<N�×$Ñ$ T×%7Ñ%7Ô8ÐTXõð Er   c                 ó  — t         j                  j                  j                  j	                  «       }|sy	 t         j                  j                  j                  j                  |«      \  }}}| j                  j                  d«      }i }|�ˆt        |dd«      |d<   t        |dt        j                  j                  «      |d<   t        |dt        j                  j                  «      |d<   t        |d	t        j                  j                  «      |d
<   d}i }	| j                  �¯| j                  j                  j                  d«      }|�ˆt        |dd«      |	d<   t        |dt        j                  j                  «      |	d<   t        |dt        j                  j                  «      |	d<   t        |d	t        j                  j                  «      |	d
<   |r*t        ||fi |¤Ž}
| j                  �t        ||fi |	¤Ž}nPd}nMt        j                  j                  di |¤Ž}
| j                  � t        j                  j                  di |	¤Ž}nd}t+        | d|
«       |�||
ur|j-                  «        | j                  �/|�-t+        | j                  d|«       |�||ur|j-                  «        || _        |r|| _        yt3        | d«      r| `yy# t        j                   t"        t$        t&        f$ r}t        j(                  |«      }||‚d}~ww xY w)a  Configure the client certificate and key for SSL connection.

        This method configures mTLS if client certificates are explicitly enabled
        (via GOOGLE_API_USE_CLIENT_CERTIFICATE=true) or auto-enabled (when the env
        variable is unset and workload certificates are discovered). In these cases,
        if the client certificate and key are successfully obtained, a
        :class:`_MutualTlsAdapter` instance will be mounted to the "https://" prefix.

        Args:
            client_cert_callback (Optional[Callable[[], (bytes, bytes)]]):
                The optional callback returns the client certificate and private
                key bytes both in PEM format.
                If the callback is None, application default SSL credentials
                will be used.

        .. warning::
            Calling this method replaces the underlying `requests.Session`
            adapters and closes the previous ones. It is not thread-safe to call
            this explicitly while other threads are making requests.

        Raises:
            google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel
                creation failed for any reason. The existing session state (such
                as adapter mounts) remains unmodified if this error is raised.
        Nrà   rp   r   r€   rq   r�   rr   r‚   rs   Ú_cached_certr%   )ÚgoogleÚauthr   r	   r~   r   rK   rŒ   ÚgetattrrB   ÚDEFAULT_POOLSIZEÚDEFAULT_POOLBLOCKrè   rg   r}   r   rŽ   ÚImportErrorr�   r­   r�   rU   rk   rå   rõ   rj   )r   Úclient_cert_callbackÚuse_client_certÚis_mtlsr‡   rI   Úold_adapterr˜   Úold_auth_adapterÚauth_kwargsr¿   Únew_auth_adapterr™   rš   s                 r   Úconfigure_mtls_channelz(AuthorizedSession.configure_mtls_channel/  s  € ô4 !Ÿ+™+×/Ñ/×<Ñ<×RÑRÓTˆÙØðD	*ô
 —‘×%Ñ%×2Ñ2×JÑJØ$óñ	ØØØð
 Ÿ-™-×+Ñ+¨JÓ7ˆKàˆFØÐ&Ü(/°¸]ÈAÓ(N��}Ñ%Ü-4ØÐ!4´h×6GÑ6G×6XÑ6Xó.�Ð)Ñ*ô *1Ø ´(×2CÑ2C×2TÑ2Tó*��~Ñ&ô (/Ø ´×0AÑ0A×0SÑ0Só(��|Ñ$ð  $ÐØˆKØ×)Ñ)Ð5Ø#'×#=Ñ#=×#FÑ#F×#JÑ#JÈ:Ó#VÐ à#Ð/Ü18Ø(¨-¸ó2�K Ñ.ô 7>Ø(Ø+Ü ×)Ñ)×:Ñ:ó7�KÐ 2Ñ3ô
 3:Ø(Ø'Ü ×)Ñ)×:Ñ:ó3�K Ñ/ô
 18Ø(Ø%Ü ×)Ñ)×;Ñ;ó1�K Ñ-ñ Ü/°°cÑD¸VÑD�Ø×-Ñ-Ð9Ü'8¸¸sÑ'RÀkÑ'RÑ$à'+Ñ$ä&×/Ñ/×;Ñ;ÑE¸fÑE�Ø×-Ñ-Ð9Ü'/×'8Ñ'8×'DÑ'DÑ'SÀ{Ñ'SÑ$à'+Ð$ô 	˜˜z¨;Ô7àÐ" {¸+Ñ'EØ×ÑÔà×%Ñ%Ð1Ð6FÐ6RÜ˜T×7Ñ7¸ÐEUÔVð !Ð,Ø$Ð,<Ñ<à ×&Ñ&Ô(àˆŒÙØ $ˆDÕä�t˜^Ô,ØÑ%ð -øô5 ×&Ñ&ÜÜÜð	
ò 	*ô !×6Ñ6°zÓBˆGØ˜zÐ)ûð	*ús   ·HK Ë#LË/LÌLc           	      ó   •— |j                  dd«      }|�|j                  «       ni }	|€| j                  n t        j                  | j                  |¬«      }
|}t        |«      5 }| j                  j                  |
|||	«       ddd«       j                  }t        | dd«      }t        |«      5 }t        j                  t        ||||«       t        t        | �>  ||f||	|dœ|¤Ž}ddd«       |j                  }j                   | j"                  v �r9|| j$                  k  �r)|j                   t&        j(                  k(  rV| j*                  xr t-        j.                  |«      }|r1t        |«      5 }| j1                  |«       ddd«       |j                  }t        j3                  d|j                   |dz   | j$                  «       |€| j                  n t        j                  | j                  |¬«      }
t        |«      5 }| j                  j5                  |
«       ddd«       |j                  } | j                  ||f|||||dz   d	œ|¤ŽS |S # 1 sw Y   �ŒÍxY w# 1 sw Y   �ŒwxY w# 1 sw Y   ŒçxY w# 1 sw Y   ŒZxY w)
a[  Implementation of Requests' request.

        Args:
            timeout (Optional[Union[float, Tuple[float, float]]]):
                The amount of time in seconds to wait for the server response
                with each individual request. Can also be passed as a tuple
                ``(connect_timeout, read_timeout)``. See :meth:`requests.Session.request`
                documentation for details.
            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.
        Raises:
            google.auth.exceptions.MutualTLSChannelError: If mutual TLS
                channel creation fails for any reason.
            ValueError: If the client certificate is invalid.
        Ú_credential_refresh_attemptr   N)r,   rõ   r‹   z;Refreshing credentials due to a %s response. Attempt %s/%s.é   )r   r   Úmax_allowed_timer,   r  )ÚpoprL   rê   Ú	functoolsÚpartialr'   rá   Úbefore_requestr*   rø   r   r‘   r’   r±   rÝ   r“   r   râ   rã   Úhttp_clientÚUNAUTHORIZEDrþ   r	   rt   Ú)_reconfigure_mtls_channel_if_cert_changedÚinfoÚrefresh)r   r–   rƒ   r   r   r  r,   r˜   r  Úrequest_headersrñ   Úremaining_timeÚguardÚcert_at_requestr   Úuse_mtlsr¸   s                   €r   r“   zAuthorizedSession.request¨  s�  ø€ ðT '-§j¡jÐ1NÐPQÓ&RÐ#ð -4Ð,?˜'Ÿ,™,œ.ÀRˆð ˆð ×Òä×"Ñ" 4×#5Ñ#5¸wÔGð 	ð *ˆä˜.Ó)ð 	X¨UØ×Ñ×+Ñ+¨L¸&À#ÀÔW÷	Xà×0Ñ0ˆô
 " $¨¸Ó=ˆä˜.Ó)ð 		¨UÜ× Ñ ¤¨&°#°t¸WÔEÜÔ.°Ñ=ØØðð Ø'Øñð ñˆH÷		ð ×0Ñ0ˆð × Ñ  D×$>Ñ$>Ò>Ø+¨d×.HÑ.HÓHð ×#Ñ#¤{×'?Ñ'?Ò?ØŸ<™<ÒN¬L×,IÑ,IÈ#Ó,N�ÙÜ% nÓ5ð X¸Ø×FÑFÀÔW÷Xà%*×%<Ñ%<�NÜ�L‰LØMØ×$Ñ$Ø+¨aÑ/Ø×*Ñ*ô	ð �?ð ×"Ò"ä×&Ñ& t×'9Ñ'9À7ÔKð ô ˜nÓ-ð 7°Ø× Ñ ×(Ñ(¨Ô6÷7à"×4Ñ4ˆNð  �4—<‘<ØØð	ð ØØ!/ØØ,GÈ!Ñ,Kñ	ð ñ	ð 	ð ˆ÷K	Xñ 	Xú÷		ñ 		ú÷2Xð Xú÷$7ð 7ús0   Á$IÂ/7IÅ0I(Ç?I4ÉIÉI%É(I1É4I=c                 óŒ  ‡‡— | j                   5  | j                  s
	 ddd«       yt        | dd«      |k7  rt        j	                  d«       	 ddd«       y	 t        j                  |«      \  ŠŠ}}||k(  rt        j	                  d«       	 ddd«       y	 t        j	                  d«       | j                  ˆˆfd„«       	 ddd«       y# t        $ r(}t        j                  d|«       Y d}~ddd«       yd}~ww xY w# t        $ r1}t        j                  d|«       t        j                  d	«      |‚d}~ww xY w# 1 sw Y   yxY w)
as  Reconfigures the mTLS channel if the client certificate has changed.

        This is called when a request to an mTLS endpoint receives a 401
        response. The certificate check and the channel reconfiguration run
        while holding ``_mtls_reauth_lock``. When several threads receive a 401
        response at the same time, only the first one reads the current
        certificate and remounts the adapters. The other threads see that the
        channel has already been reconfigured and reuse it.

        Args:
            cert_at_request (Optional[bytes]): The cached client certificate at
                the time the request that received the 401 response was sent.

        Raises:
            google.auth.exceptions.MutualTLSChannelError: If the client
                certificate has changed but the mTLS channel could not be
                reconfigured.
        Nrõ   zpSkipping reconfiguration of mTLS channel because it has already been reconfigured with a new client certificate.z>Failed to check whether the client certificate has changed: %szXSkipping reconfiguration of mTLS channel because the client certificate has not changed.z;Client certificate has changed, reconfiguring mTLS channel.c                  ó   •— ‰ ‰fS r   r%   )Úcall_cert_bytesÚcall_key_bytess   €€r   rH   zMAuthorizedSession._reconfigure_mtls_channel_if_cert_changed.<locals>.<lambda>f  s   ø€ °_ÀnÐ4U€ r   z&Failed to reconfigure mTLS channel: %sz"Failed to reconfigure mTLS channel)rç   rþ   rø   r’   r  r	   Ú*check_parameters_for_unauthorized_responseÚ	ExceptionÚwarningr  Úerrorr   r�   )r   r  Úcached_fingerprintÚcurrent_cert_fingerprintÚer  r  s        @@r   r  z;AuthorizedSession._reconfigure_mtls_channel_if_cert_changed)  s[  ù€ ð& ×#Ñ#ñ /	Ø—<’<à÷/	ð /	ô
 �t˜^¨TÓ2°oÒEÜ—‘ðHôð ÷/	ð /	ðô !×KÑKØ#óñØ#Ø"Ø&Ø,ð "Ð%=Ò=Ü—‘ð4ôð ÷I/	ð /	ðL	Ü—‘ØQôð ×+Ñ+Ô,UÕV÷U/	ð /	øô* ò ô —‘ØTØôó ÷;/	ð /	ûð*ûô, ò Ü—‘ÐFÈÔJÜ ×6Ñ6Ø8óàðûðú÷W/	ð /	úsX   �D:¦&D:ÁC	Á0D:Â*C=Ã		C:ÃC5Ã(D:Ã5C:Ã:D:Ã=	D7Ä,D2Ä2D7Ä7D:Ä:Ec                 ó   — | j                   S )z3Indicates if the created SSL channel is mutual TLS.)rå   r   s    r   rþ   zAuthorizedSession.is_mtlsm  s   € ð �}‰}Ðr   c                 óv   •— | j                   �| j                   j                  «        t        t        | �  «        y r   )rè   rk   r±   rÝ   )r   r¸   s    €r   rk   zAuthorizedSession.closer  s/   ø€ Ø×%Ñ%Ð1Ø×&Ñ&×,Ñ,Ô.ÜÔ Ñ,Õ.r   r   )r    r!   r"   r#   r   ÚDEFAULT_REFRESH_STATUS_CODESÚDEFAULT_MAX_REFRESH_ATTEMPTSr   r  rœ   r“   r  r$   rþ   rk   rÌ   rÍ   s   @r   rÝ   rÝ   ¬  sn   ø„ ñTðr '×CÑCØ&×CÑCØØØõ*óXw&ðz ØØØ õòBBðH ñó ð÷/ð /r   rÝ   )3r#   Ú
__future__r   rM   rL   r	  Úhttp.clientÚclientr  Úloggingr9   r]   r/   Úurllib.parseÚparseru   Útypingr   rB   rû   r™   Úrequests.adaptersÚrequests.exceptionsÚ#requests.packages.urllib3.util.ssl_r   Ú"google.auth.transport._mtls_helperrö   Úgoogle.authr   r   r   rÒ   r	   Úgoogle.oauth2r
   Ú	getLoggerr    r’   rœ   ÚResponser   rº   r'   rU   rW   rK   r}   rg   rÏ   rZ   rÝ   r%   r   r   ú<module>r4     s  ðñ &å &ã Û Û Ý !Û Û Û Û Ý #Ý ðÛó
 Û õó *ß 7Ñ 7Ý .Ý )à
ˆ'×
Ñ
˜HÓ
%€àÐ ô&�	×"Ñ"ô &ô.)-�6ô )-òXô2V*ˆi×Ñô V*ôrMQ˜×)Ñ)×5Ñ5ô MQô`0X˜x×0Ñ0×<Ñ<ô 0XôfI/˜×(Ñ(õ I/øðY ò Ù
Øwóàðûðús   ¸D ÄDÄ		DÄD