
    gI                         d Z ddlZddl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  G d d	ej                        Z G d
 dej                        Zy# e$ rZ ed      edZ[ww xY w)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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     V/var/www/openai/venv/lib/python3.12/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                 ~    | j                   j                  j                         D ci c]  \  }}||
 c}}S c c}}w r   )r   headersitems)r   keyvalues      r   r   zResponse.headers5   s9     .2^^-C-C-I-I-KL-KzsEU
-K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.content:   so     	#~~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.readF   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.closeM   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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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_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| _        y )NF)_session_closed)r   r8   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{   }t        |      S 7 # t        j                  $ r!}	t        j                  d| d      }
|
|	d}	~	wt        j                  $ r!}	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   r@   NzFailed to send request to .zRequest timed out after z	 seconds.)r;   r   TransportErrorr:   r!   ClientSessionClientTimeoutrequestr
   ClientErrorasyncioTimeoutError)r   r=   r>   r?   r   r@   kwargsclient_timeoutr   
caught_exc
client_exctimeout_excs               r   __call__zRequest.__call__t   s	    D	.|| //0DEE== ' 5 5 7$22AN2T]]22 &  H H%% "" 	-#225OPSuTU3VWJ*,## 	.$11*7)9=K :-		.sG   D BB BB D B C=*CC=C88C==D 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,   r-   r.   r!   rF   r   r   _DEFAULT_TIMEOUT_SECONDSr3   r   r4   r   floatr
   rQ   r*   r5   r   r   r7   r7   R   s    : 5 5   $/3";;<.<. <. uo	<.
 '#s(+,<. <. 
		<.|r   r7   )r.   rJ   typingr   r   r   r!   ImportErrorrN   google.authr   r   google.auth.aior   r
   r7   r5   r   r   <module>rY      su     4 4 ! " %.y!! .bfi fw  
ts   A A&	A!!A&