
    Oja                        S r SSKJr  SSKrSSKJr  SSKrSSKrSSK	r	SSK
J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  SSKrSSKJr  \R:                  " \5      rSr  " S S\RB                  5      r" " S S\#5      r$ " S S\RJ                  5      r% " S S\RL                  RN                  5      r( " S S\RL                  RN                  5      r) " S S\RT                  5      r+g! \ a  r\" S5      \eSrCff = f)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_accountx   c                   N    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	Sr
g)		_Response2   ziRequests transport response adapter.

Args:
    response (requests.Response): The raw Requests response.
c                     Xl         g N	_response)selfresponses     `/var/www/html/leaf-doctor-v1/venv/lib/python3.13/site-packages/google/auth/transport/requests.py__init___Response.__init__9   s    !    c                 .    U R                   R                  $ r   )r   status_coder   s    r   status_Response.status<   s    ~~)))r   c                 .    U R                   R                  $ r   )r   headersr   s    r   r   _Response.headers@       ~~%%%r   c                 .    U R                   R                  $ r   )r   contentr   s    r   data_Response.dataD   r!   r   r   N)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r$   __static_attributes__ r   r   r   r   2   sH    " * * & & & &r   r   c                   X    \ rS rSrSr\R                  R                  4S jrS r	S r
Srg)TimeoutGuardI   a-  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                 (    Xl         Xl        X l        g r   )_timeoutremaining_timeout_timeout_error_type)r   timeouttimeout_error_types      r   r   TimeoutGuard.__init__W   s    !(#5 r   c                 :    [         R                   " 5       U l        U $ r   )time_startr   s    r   	__enter__TimeoutGuard.__enter__\   s    iikr   c                   ^ U(       a  g U R                   c  g [        R                  " 5       U R                  -
  mSn[        U R                   [        R
                  5      (       a$  U R                   T-
  U l        U R                  S:*  nO<[        U4S jU R                    5       5      U l        [        U R                  5      S:*  nU(       a  U R                  5       eg )NFr   c              3   ,   >#    U  H	  oT-
  v   M     g 7fr   r-   ).0xelapseds     r   	<genexpr>(TimeoutGuard.__exit__.<locals>.<genexpr>n   s     *N1w;s   )
r2   r9   r:   
isinstancenumbersNumberr3   tupleminr4   )r   exc_type	exc_value	tracebackdeadline_hitrA   s        @r   __exit__TimeoutGuard.__exit__`   s    == ))++dmmW^^44%)]]W%<D"11Q6L%**N*N%ND"t556!;L**,, r   )r:   r2   r4   r3   N)r&   r'   r(   r)   r*   requestsr   Timeoutr   r;   rM   r,   r-   r   r   r/   r/   I   s'     4<3F3F3N3N 6
-r   r/   c                   `    \ rS rSrSrSS\\R                     SS4S jjrS r	SSS\
4S	 jrS
rg)Requestu   a  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__
Nsessionreturnc                 H    U(       d  [         R                  " 5       nXl        g r   )rO   SessionrT   )r   rT   s     r   r   Request.__init__   s    &&(Gr   c                      [        U S5      (       a)  U R                  b  U R                  R                  5         g g g ! [         a     g f = f)NrT   )hasattrrT   close	TypeErrorr   s    r   __del__Request.__del__   sJ    	tY''DLL,D""$ -E' 	 		s   8= 
A
	A
GETc                 D    [         R                  " [        X!X45        U R                  R                  " X!4X4US.UD6n[         R
                  " [        U5        [        U5      $ ! [        R                  R                   a  n[        R                  " U5      n	XeSnAff = f)a  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$   r   r5   N)r   request_log_LOGGERrT   requestresponse_logr   rO   r   RequestExceptionTransportError)
r   urlmethodbodyr   r5   kwargsr   
caught_excnew_excs
             r   __call__Request.__call__   s    :		*  &tE||++"&LRH !!'84X&&""33 	* //
;G)	*s   A!A$ $BBB)rT   r   )r&   r'   r(   r)   r*   r   rO   rW   r   r]   _DEFAULT_TIMEOUTrn   r,   r-   r   r   rR   rR   u   s=    .)9)9 : d   &*r   rR   c                   D   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrSrU =r	$ )_MutualTlsAdapter   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                 ~  > SS K nSS Kn[        5       nUR                  UR	                  5       S9  [        5       nUR                  UR	                  5       S9   [
        R                  " X5       u  nnn	[        U	[        5      (       a  U	R                  S5      OU	n
UR                  UUU
S9  UR                  UUU
S9  S S S 5        XPl        X`l        [*        [,        U ]_  5         g ! , (       d  f       N-= f! UR                  [        [        [        [        [         4 a  n["        R$                  " S5      UeS nAff = f)Nr   cafilezutf-8)certfilekeyfilepasswordz8Failed to configure client certificate and key for mTLS.)certifisslr   load_verify_locationswherer	   secure_cert_key_pathsrD   bytesdecodeload_cert_chainSSLErrorOSErrorIOError
ValueErrorRuntimeErrorr\   r   MutualTLSChannelError_ctx_poolmanager_ctx_proxymanagersuperrr   r   )r   certkeyrz   r{   ctx_poolmanagerctx_proxymanager	cert_pathkey_path
passphrasery   exc	__class__s               r   r   _MutualTlsAdapter.__init__   s=   02--W]]_-E13..gmmo.F	33D> C "*e44 %%g.# 
  //&$% 0 
 !00&$% 1  ?@ !0!1/1G ?>* LL
 
	 22J
	s7   C6 /AC%>C6 %
C3/C6 3C6 6*D< D77D<c                 L   > U R                   US'   [        [        U ]  " U0 UD6  g Nssl_context)r   r   rr   init_poolmanagerr   argsrk   r   s      r   r   "_MutualTlsAdapter.init_poolmanager  s(     $ 5 5}7HHr   c                 J   > U R                   US'   [        [        U ]  " U0 UD6$ r   )r   r   rr   proxy_manager_forr   s      r   r   #_MutualTlsAdapter.proxy_manager_for  s+     $ 6 6}&?PPPr   )r   r   
r&   r'   r(   r)   r*   r   r   r   r,   __classcell__r   s   @r   rr   rr      s     
.2`IQ Qr   rr   c                   D   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrSrU =r	$ )_MutualTlsOffloadAdapteri  aF  
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                   > SS K nSSKJn  UR                  U5      U l        U R                  R                  5         [        5       nUR                  UR                  5       S9  U R                  R                  U5        X@l
        [        5       nUR                  UR                  5       S9  U R                  R                  U5        XPl        [        [        U ];  5         g )Nr   )_custom_tls_signerru   )rz   google.auth.transportr   CustomTlsSignersignerload_librariesr   r|   r}   attach_to_ssl_contextr   r   r   r   r   )r   enterprise_cert_file_pathrz   r   poolmanagerproxymanagerr   s         r   r   !_MutualTlsOffloadAdapter.__init__"  s    <(889RS""$,.)))A))+6 +-/**'--/*B)),7!-&68r   c                 L   > U R                   US'   [        [        U ]  " U0 UD6  g r   )r   r   r   r   r   s      r   r   )_MutualTlsOffloadAdapter.init_poolmanager5  s(     $ 5 5}&>OOr   c                 J   > U R                   US'   [        [        U ]  " U0 UD6$ r   )r   r   r   r   r   s      r   r   *_MutualTlsOffloadAdapter.proxy_manager_for9  s,     $ 6 6}-tFWPVWWr   )r   r   r   r   r   s   @r   r   r     s    *9&PX Xr   r   c                      ^  \ rS rSrSr\R                  \R                  SSS4U 4S jjrS
S jr	SSS\
4U 4S jjr\S 5       rU 4S jrS	rU =r$ )AuthorizedSessioni>  a  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                 H  > [         [        U ]  5         Xl        X l        X0l        X@l        SU l        X`l        Uci  [        R                  " 5       U l        [        R                  R                  SS9nU R                  R                  SU5        [        U R                  5      nOS U l        XPl        [#        U R                  [$        R&                  5      (       aH  U R                  R)                  U R                  (       a  SR+                  U R                  5      OS 5        g g )NF   )max_retrieshttps://zhttps://{}/)r   r   r   credentials_refresh_status_codes_max_refresh_attempts_refresh_timeout_is_mtls_default_hostrO   rW   _auth_request_sessionadaptersHTTPAdaptermountrR   _auth_requestrD   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   AuthorizedSession.__init__  s     	/1&%9"%9" /))1)9)9);D&
 %--99a9HM&&,,ZG #4#=#=>L)-D& * d&&(C(CDD44<@<N<N$$T%7%78TX Er   c                 H   [         R                  R                  R                  R	                  5       nU(       d  g [         R                  R                  R                  R                  U5      u  nnnU(       a  [        XE5      nO[        R                  R                  5       n U R!                  SU5        X0l        U(       a  X@l        g['        U S5      (       a  U ?gg! [        R                  [        [        [        4 a  n[        R                  " U5      nXeSnAff = f)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.

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   _cached_cert)googleauthr   r	   check_use_client_certget_client_cert_and_keyrr   rO   r   r   r   ClientCertErrorImportErrorr   r   r   r   r   r   rZ   )	r   client_cert_callbackuse_client_certis_mtlsr   r   new_adapterrl   rm   s	            r   configure_mtls_channel(AuthorizedSession.configure_mtls_channel  s    * !++//<<RRT	*
 %%22JJ$	
 /:&//;;= 	

:{+ $t^,,% - &&	
 	* !66zBG)	*s   A	C  C   $D!DD!c           	        >^^ 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[        U5       nU R                  R                  XX)5        SSS5        WR                  n[        U5       n[        R                  " [        XX45        [        [        U ]:  " UU4UU	US.UD6nSSS5        UR                  nWR                  U R                   ;   Ga`  XR"                  :  GaP  UR                  [$        R&                  :X  a}  U R(                  (       al  [*        R,                  " U R.                  5      u  mmnnX:w  a-   [        R1                  S5        U R3                  UU4S j5        O[        R1                  S
5        [        R1                  SUR                  US-   U R"                  5        Uc  U R                  O[        R                  " U R                  US9n
[        U5       nU R                  R=                  U
5        SSS5        UR                  nU R                  " UU4UUUUUS-   S.UD6$ U$ ! , (       d  f       GN= f! , (       d  f       GN= f! [4         a2  n[        R7                  SU5        [8        R:                  " S	5      UeSnAff = f! , (       d  f       N= f)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)r5   ra   z;Client certificate has changed, reconfiguring mTLS channel.c                     > T T4$ r   r-   )call_cert_bytescall_key_bytess   r   <lambda>+AuthorizedSession.request.<locals>.<lambda>\  s
    .(Ir   z&Failed to reconfigure mTLS channel: %sz"Failed to reconfigure mTLS channelzXSkipping reconfiguration of mTLS channel because the client certificate has not changed.z;Refreshing credentials due to a %s response. Attempt %s/%s.   )r$   r   max_allowed_timer5   r   )popcopyr   	functoolspartialr/   r   before_requestr3   r   rb   rc   r   r   rd   r   r   r   http_clientUNAUTHORIZEDr   r	   *check_parameters_for_unauthorized_responser   infor   	Exceptionerrorr   r   refresh)r   ri   rh   r$   r   r   r5   rk   r   request_headersr   remaining_timeguardr   cached_fingerprintcurrent_cert_fingerprinter   r   r   s                    @@r   rd   AuthorizedSession.request  s   T '-jj1NPQ&R# -4,?',,.R  ""4#5#5wG 	 *.)U++L#W *00.)U  &tE.= ' H * 00   D$>$>>+.H.HH ##{'?'??<< %OO))'&*0 *E%#LL!+ !77 I  < LLM$$+a/**	 ? ""&&t'9'97K  n-  ((6 ."44N <<	 !/,G!,K	 	 	 o *) *)R  ) %#MM*RTUV","B"B D##$%%2 .-s<   &I*"7I<2+J K*
I9<
J
K
-KK

Kc                     U R                   $ )z3Indicates if the created SSL channel is mutual TLS.)r   r   s    r   r   AuthorizedSession.is_mtls  s     }}r   c                 x   > U R                   b  U R                   R                  5         [        [        U ]  5         g r   )r   r[   r   r   )r   r   s    r   r[   AuthorizedSession.close  s/    %%1&&,,.,.r   )	r   r   r   r   r   r   r   r   r   r   )r&   r'   r(   r)   r*   r   DEFAULT_REFRESH_STATUS_CODESDEFAULT_MAX_REFRESH_ATTEMPTSr   r   rp   rd   r+   r   r[   r,   r   r   s   @r   r   r   >  sf    Tr 'CC&CC)V5&v  Qf  / /r   r   ),r*   
__future__r   r   http.clientclientr   loggingrE   r9   typingr   rO   r   rl   requests.adaptersrequests.exceptions#requests.packages.urllib3.util.ssl_r   google.authr   r   r   r   r	   "google.auth.transport._mtls_helperr   google.oauth2r
   	getLoggerr&   rc   rp   Responser   objectr/   rR   r   r   rr   r   rW   r   r-   r   r   <module>r     s   & &  !    
   ! " ! . ) )


H
% &	"" &.)-6 )-XN*i N*bCQ))55 CQL/Xx00<< /XdT/(( T/E	  
ws   C7 7D=	DD