
    8	iC                        d Z ddl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 ddlmZ  ej        e          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     Y/srv/django_bis/venv311/lib/python3.11/site-packages/google/auth/aio/transport/aiohttp.py__init__zResponse.__init__1   s    !    returnc                     | j         j        S r   )r   statusr   s    r   status_codezResponse.status_code4   s     ~$$r   c                 R    d | j         j                                        D             S )Nc                     i | ]\  }}||	S  r   ).0keyvalues      r   
<dictcomp>z$Response.headers.<locals>.<dictcomp><   s    LLLzsEULLLr   )r   headersitemsr   s    r   r   zResponse.headers9   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.readJ   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.closeQ   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__t   s    r   GETurlmethodbodyr   timeoutr   c                 8  K   	 | j         rt          j        d          | j        st	          j                    | _        t	          j        |          }t          j        t          ||||            | j        j
        ||f|||d| d{V }t          j        t          |           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ClientTimeoutr   request_log_LOGGERrequest_helpers_asyncresponse_log_asyncr
   ClientErrorasyncioTimeoutError)r   rA   rB   rC   r   rD   kwargsclient_timeoutr   
caught_exc
client_exctimeout_excs               r   __call__zRequest.__call__x   s     D	.| F /0DEEE= 8 ' 5 7 7$2AAAN &#tWEEE2T]2 &         H !3GXFFFFFFFFFH%%%" 	- 	- 	-#23VPS3V3V3VWWJ*,# 	. 	. 	.$1=7=== K :-		.s$   B8B= =DC''D9DD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
   rY   r/   r   r   r   r;   r;   V   s         :  5      $/3";>. >.>. >. uo	>.
 '#s(+,>. >. 
	>. >. >. >.@     r   r;   )r3   rR   loggingtypingr   r   r   r&   ImportErrorrV   google.authr   r   google.auth.aiorO   r   	getLoggerr0   rM   r
   r;   r   r   r   <module>rc      sU      4 4 4 4 4 4 4 4 4 4NNNN   
+t 
 !           " " " " " " 6 6 6 6 6 6 % % % % % %
'
H
%
%. . . . .y! . . .bh h h h hi h h h h hs    1,1