
    &gI                         d Z ddlZddlmZmZmZ 	 ddlZn# e$ rZ ed          edZ[ww xY wddl	m
Z
 ddl	mZ ddlmZ  G d d	ej                  Z G d
 dej                  ZdS )zCTransport adapter for Asynchronous HTTP Requests based on aiohttp.
    N)AsyncGeneratorMappingOptionalzjThe aiohttp library is not installed from please install the aiohttp package to use the aiohttp transport.)_helpers)
exceptions)	transportc                      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d	S )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                     || _         d S N)	_response)selfr   s     S/var/www/api/venv/lib/python3.11/site-packages/google/auth/aio/transport/aiohttp.py__init__zResponse.__init__-   s    !    returnc                     | j         j        S r   )r   statusr   s    r   status_codezResponse.status_code0   s     ~$$r   c                 R    d | j         j                                        D             S )Nc                     i | ]\  }}||	S  r   ).0keyvalues      r   
<dictcomp>z$Response.headers.<locals>.<dictcomp>8   s    LLLzsEULLLr   )r   headersitemsr   s    r   r   zResponse.headers5   s*     MLT^-C-I-I-K-KLLLLr      
chunk_sizeNc                   K   	 | j         j                            |          2 3 d {V }|W V  6 d S # t          j        $ r}t          j        d          |d }~ww xY w)Nz'Failed to read from the payload stream.)r   contentiter_chunkedaiohttpClientPayloadErrorr   ResponseError)r   r"   chunkexcs       r   r$   zResponse.content:   s      	#~5BB          e       ) 	 	 	*9 	s   3 03 AAAc                    K   	 | j                                          d {V S # t          j        $ r}t	          j        d          |d }~ww xY w)Nz!Failed to read the response body.)r   readr&   ClientResponseErrorr   r(   )r   r*   s     r   r,   zResponse.readF   sm      	Y,,.........* 	Y 	Y 	Y*+NOOUXX	Ys   # AAAc                 <   K   | j                                          d S r   )r   closer   s    r   r/   zResponse.closeM   s       r   )r!   )__name__
__module____qualname____doc__r&   ClientResponser   propertyr   copy_docstringr   r
   intr   r   strr   r   bytesr$   r,   r/   r   r   r   r
   r
   !   s       	 	"!7 " " " " XY/00%S % % % 10 X% XY/00Mc* M M M 10 XM XY/00	 	 	~eTk7R 	 	 	 10	 XY/00YE Y Y Y 10Y XY/00  10  r   r
   c                       e Zd ZdZdd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dej        fdZddZdS )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_sesion = 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| _        d S )NF)_session_closed)r   r<   s     r   r   zRequest.__init__p   s    r   GETurlmethodbodyr   timeoutr   c                   K   	 | j         rt          j        d          | j        st	          j                    | _        t	          j        |          } | j        j        ||f|||d| d{V }t          |          S # t          j	        $ r }	t          j        d| d          }
|
|	d}	~	wt          j        $ r }	t          j        d| d          }||	d}	~	ww xY 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   rD   NzFailed to send request to .zRequest timed out after z	 seconds.)r?   r   TransportErrorr>   r&   ClientSessionClientTimeoutrequestr
   ClientErrorasyncioTimeoutError)r   rA   rB   rC   r   rD   kwargsclient_timeoutr   
caught_exc
client_exctimeout_excs               r   __call__zRequest.__call__t   sI     D	.| F /0DEEE= 8 ' 5 7 7$2AAAN2T]2 &         H H%%%" 	- 	- 	-#23VPS3V3V3VWWJ*,# 	. 	. 	.$1=7=== K :-		.s$   A;B   CB**C<CCc                 r   K   | j         s&| j        r| j                                         d{V  d| _         dS )zY
        Close the underlying aiohttp session to release the acquired resources.
        NT)r?   r>   r/   r   s    r   r/   zRequest.close   sL       | 	( 	(-%%'''''''''r   r   )r   N)r0   r1   r2   r3   r&   rJ   r   r   _DEFAULT_TIMEOUT_SECONDSr8   r   r9   r   floatr
   rU   r/   r   r   r   r;   r;   R   s         :  5      $/3";<. <.<. <. uo	<.
 '#s(+,<. <. 
	<. <. <. <.|     r   r;   )r3   rN   typingr   r   r   r&   ImportErrorrR   google.authr   r   google.auth.aior   r
   r;   r   r   r   <module>r]      s(     4 4 4 4 4 4 4 4 4 4NNNN   
+t 
 !           " " " " " " % % % % % %. . . . .y! . . .bf f f f fi f f f f fs    -(-