
    p[i                     P   d Z ddlZddlZddlmZmZmZmZm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 erddl	mZ n	 ddl	mZ  ej(                  e      Z G d	 d
ej.                        Z G d dej0                        Zy# e
$ rZ e
d      edZ[ww xY w# e
ef$ r dZY ^w xY w)zBTransport adapter for Asynchronous HTTP Requests based on aiohttp.    N)AsyncGeneratorMappingOptionalTYPE_CHECKINGUnionzjThe aiohttp library is not installed from please install the aiohttp package to use the aiohttp transport.)_helpers)
exceptions)	transport)ClientTimeoutc                      e Zd ZdZdej
                  fdZe ej                  e
j                        defd              Ze ej                  e
j                        deeef   fd              Z ej                  e
j                        ddedeedf   fd	       Z ej                  e
j                        defd
       Z ej                  e
j                        d        Zy)Responseaz  
    Represents an HTTP response and its data. It is returned by ``google.auth.aio.transport.sessions.AsyncAuthorizedSession``.

    Args:
        response (aiohttp.ClientResponse): An instance of aiohttp.ClientResponse.

    Attributes:
        status_code (int): The HTTP status code of the response.
        headers (Mapping[str, str]): The HTTP headers of the response.
    responsec                     || _         y N)	_response)selfr   s     Z/mnt/data/GridWatch/venv/lib/python3.12/site-packages/google/auth/aio/transport/aiohttp.py__init__zResponse.__init__9   s	    !    returnc                 .    | j                   j                  S r   )r   statusr   s    r   status_codezResponse.status_code<   s     ~~$$$r   c                 ~    | j                   j                  j                         D ci c]  \  }}||
 c}}S c c}}w r   )r   headersitems)r   keyvalues      r   r   zResponse.headersA   s3     .2^^-C-C-I-I-KLzsEU
LLLs   9
chunk_sizeNc                   K   	 | j                   j                  j                  |      2 3 d {   }| 7 
6 y # t        j                  $ r}t        j                  d      |d }~ww xY ww)Nz'Failed to read from the payload stream.)r   contentiter_chunkedaiohttpClientPayloadErrorr	   ResponseError)r   r    chunkexcs       r   r"   zResponse.contentF   st     	#~~55BB   e    )) 	**9	s=   A-%< :8:< :< A-A*A%%A**A-c                    K   	 | j                   j                          d {   S 7 # t        j                  $ r}t	        j
                  d      |d }~ww xY ww)Nz!Failed to read the response body.)r   readr$   ClientResponseErrorr	   r&   )r   r(   s     r   r*   zResponse.readR   sQ     	Y,,....** 	Y**+NOUXX	Ys0   A( &( A( AAAAc                 @   K   | j                   j                          y wr   )r   closer   s    r   r-   zResponse.closeY   s     s   )i   )__name__
__module____qualname____doc__r$   ClientResponser   propertyr   copy_docstringr
   r   intr   r   strr   r   bytesr"   r*   r-    r   r   r   r   -   s'   	"!7!7 " XY//0%S % 1 % XY//0Mc* M 1 M XY//0	 	~eTk7R 	 1	 XY//0YE Y 1Y XY//0 1r   r   c                       e Zd ZdZddeej                     fdZdddej                  fde
de
dee   d	eee
e
f      d
eeef   dej                   fdZddZy)Requesta  Asynchronous Requests request adapter.

    This class is used internally for making requests using aiohttp
    in a consistent way. If you use :class:`google.auth.aio.transport.sessions.AsyncAuthorizedSession`
    you do not need to construct or use this class directly.

    This class can be useful if you want to configure a Request callable
    with a custom ``aiohttp.ClientSession`` in :class:`AuthorizedSession` or if
    you want to manually refresh a :class:`~google.auth.aio.credentials.Credentials` instance::

        import aiohttp
        import google.auth.aio.transport.aiohttp

        # Default example:
        request = google.auth.aio.transport.aiohttp.Request()
        await credentials.refresh(request)

        # Custom aiohttp Session Example:
        session = session=aiohttp.ClientSession(auto_decompress=False)
        request = google.auth.aio.transport.aiohttp.Request(session=session)
        auth_session = google.auth.aio.transport.sessions.AsyncAuthorizedSession(auth_request=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__
    Nsessionc                      || _         d| _        y )NF)_session_closed)r   r;   s     r   r   zRequest.__init__|   s    r   GETurlmethodbodyr   timeoutr   c                   K   	 | j                   rt        j                  d      | j                  st	        j
                         | _        t        |t        j                        r|}nt	        j                  |      }t        j                  t        ||||        | j                  j                  ||f|||d| d{   }t        j                  t        |       d{    t        |      S 7 17 # t        j                  $ r!}	t        j                  d| d      }
|
|	d}	~	wt         j"                  $ rJ}	t        |t        j                        r|j$                  }n|}t        j"                  d| d      }||	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 (float): 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
                aiohttp :meth:`aiohttp.Session.request` method.

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

        Raises:
            - google.auth.exceptions.TransportError: If the request fails or if the session is closed.
            - google.auth.exceptions.TimeoutError: If the request times out.
        zsession is closed.)total)datar   rC   NzFailed to send request to .zRequest timed out after z	 seconds.)r>   r	   TransportErrorr=   r$   ClientSession
isinstancer   r   request_log_LOGGERrequest_helpers_asyncresponse_log_asyncr   ClientErrorasyncioTimeoutErrorrE   )r   r@   rA   rB   r   rC   kwargsclient_timeoutr   
caught_exc
client_exctimeout_secondstimeout_excs                r   __call__zRequest.__call__   sp    D#	.|| //0DEE== ' 5 5 7'7#8#89!(!(!6!6W!E  &#tWE2T]]22 &  H !33GXFFFH%% G "" 	-#225OPSuTU3VWJ*,## 	.'7#8#89")--")$11*?*;9EK :-	.sZ   FB;C5 ?C1 !C5 !C3"C5 0F1C5 3C5 5FD$$F:AE??FFc                    K   | j                   s.| j                  r"| j                  j                          d{    d| _         y7 w)zY
        Close the underlying aiohttp session to release the acquired resources.
        NT)r>   r=   r-   r   s    r   r-   zRequest.close   s7      ||--%%''' (s   6AAAr   )r   N)r.   r/   r0   r1   r   r$   rI   r   r
   _DEFAULT_TIMEOUT_SECONDSr6   r7   r   r   floatr   r   rY   r-   r8   r   r   r:   r:   ^   s    :)>)> ?   $/3/8/Q/QE.E. E. uo	E.
 '#s(+,E. um+,E. 
		E.Nr   r:   )r1   rQ   loggingtypingr   r   r   r   r   r$   ImportErrorrU   google.authr   r	   google.auth.aiorN   r
   r   AttributeError	getLoggerr.   rL   r   r:   r8   r   r   <module>rd      s    I   J J ! " 6 %%) '

H
%.y!! .boi oO  
t  ( s)   B  B B	BB	B%$B%