o
    Þ­j€  ã                
   @   s   d Z ddlZddlZddlmZmZmZmZmZ zddl	Z	W n e
y/ Z ze
dƒe‚dZ[ww ddlmZ ddlmZ ddlmZ ddlmZ erQddl	mZ nzddl	mZ W n e
efyf   dZY nw e e¡ZG d	d
„ d
ejƒZG dd„ dejƒZdS )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                   @   sº   e Zd ZdZdejfdd„Zee 	e
j¡defdd„ƒƒZee 	e
j¡deeef fdd	„ƒƒZe 	e
j¡ddedeedf fdd„ƒZe 	e
j¡defdd„ƒZe 	e
j¡d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                 C   s
   || _ d S ©N)Ú	_response)Úselfr   © r   ú^/var/www/html/CropPilot/venv/lib/python3.10/site-packages/google/auth/aio/transport/aiohttp.pyÚ__init__9   s   
zResponse.__init__Úreturnc                 C   s   | j jS r   )r   Ústatus©r   r   r   r   Ústatus_code<   s   zResponse.status_codec                 C   s   dd„ | j j ¡ D ƒS )Nc                 S   s   i | ]\}}||“qS r   r   )Ú.0ÚkeyÚvaluer   r   r   Ú
<dictcomp>D   s    z$Response.headers.<locals>.<dictcomp>)r   ÚheadersÚitemsr   r   r   r   r   A   s   zResponse.headersé   Ú
chunk_sizeNc              
   C  sT   �z| j j |¡2 z	3 d H W }|V  q	6 W d S  tjy) } zt d¡|‚d }~ww )Nz'Failed to read from the payload stream.)r   ÚcontentÚiter_chunkedÚaiohttpÚClientPayloadErrorr   ÚResponseError)r   r   ÚchunkÚexcr   r   r   r   F   s   €ÿýÿþ€ÿzResponse.contentc              
   Ã   s<   �z	| j  ¡ I d H W S  tjy } zt d¡|‚d }~ww )Nz!Failed to read the response body.)r   Úreadr!   ÚClientResponseErrorr   r#   )r   r%   r   r   r   r&   R   s   €€ÿzResponse.readc                 Ã   s   �| j  ¡  d S r   )r   Úcloser   r   r   r   r(   Y   s   €zResponse.close)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   ÚClientResponser   Úpropertyr   Úcopy_docstringr	   r   Úintr   r   Ústrr   r   Úbytesr   r&   r(   r   r   r   r   r   -   s    




r   c                   @   sx   e Zd ZdZddeej fd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d„Zd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_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                 C   s   || _ d| _d S )NF)Ú_sessionÚ_closed)r   r4   r   r   r   r   |   s   
zRequest.__init__ÚGETÚurlÚmethodÚbodyr   Útimeoutr   c              
   Ë   s  �zH| j r
t d¡‚| jst ¡ | _t|tjƒr|}ntj|d�}t 	t
||||¡ | jj||f|||dœ|¤ŽI dH }t t
|¡I dH  t|ƒW S  tjyb }	 zt d|› d�¡}
|
|	‚d}	~	w tjy† }	 zt|tjƒrt|j}n|}t d|› d�¡}||	‚d}	~	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.)r6   r   ÚTransportErrorr5   r!   ÚClientSessionÚ
isinstancer
   r   Úrequest_logÚ_LOGGERÚrequestÚ_helpers_asyncÚresponse_log_asyncr   ÚClientErrorÚasyncioÚTimeoutErrorr<   )r   r8   r9   r:   r   r;   ÚkwargsÚclient_timeoutr   Ú
caught_excÚ
client_excÚtimeout_secondsÚtimeout_excr   r   r   Ú__call__€   sH   €"

þûú
€
ÿ€øzRequest.__call__c                 Ã   s(   �| j s| jr| j ¡ I dH  d| _ dS )zY
        Close the underlying aiohttp session to release the acquired resources.
        NT)r6   r5   r(   r   r   r   r   r(   Ç   s   €
zRequest.closer   )r   N)r)   r*   r+   r,   r   r!   r@   r   r	   Ú_DEFAULT_TIMEOUT_SECONDSr1   r2   r   r   Úfloatr
   r   rP   r(   r   r   r   r   r3   ^   s*    úþýüû
ú
øGr3   )r,   rH   ÚloggingÚtypingr   r   r   r   r   r!   ÚImportErrorrL   Úgoogle.authr   r   Úgoogle.auth.aiorE   r	   r
   ÚAttributeErrorÚ	getLoggerr)   rC   r   r3   r   r   r   r   Ú<module>   s8   ÿþ€ÿÿ
1