o
    tBh4                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
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mZ d dlmZmZmZ d d	lmZ d
dl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z)m*Z* e+e,Z-G dd de%Z.dS )    N)
SSLContext)AnyAsyncGeneratorCallableDictOptionalTupleTypeUnion)ClientResponseError)Fingerprint)	BasicAuth)LooseCookiesLooseHeaders)DocumentNodeExecutionResult	print_ast)CIMultiDictProxy   )extract_files   )AppSyncAuthentication)AsyncTransport)TransportAlreadyConnectedTransportClosedTransportProtocolErrorTransportServerErrorc                   @   s\  e Zd ZU dZejejefZ	e
ee df ed< ddddddejdfdedee d	ee d
eeedf  deeeef dee deeeef  dedeeeef  ddfddZd#ddZede j!fddZ"d#ddZ#				d$de$deeeef  dee deeeef  dede%fdd Z&		d%de$deeeef  dee dee%df fd!d"Z'dS )&AIOHTTPTransportz:ref:`Async Transport <async_transports>` to execute GraphQL queries
    on remote servers with an HTTP connection.

    This transport use the aiohttp library with asyncio.
    .file_classesNF
   urlheaderscookiesauthr   ssltimeoutssl_close_timeoutjson_serializeclient_session_argsreturnc
           
      C   sD   || _ || _|| _|| _|| _|| _|| _|	| _d| _|  || _	dS )a  Initialize the transport with the given aiohttp parameters.

        :param url: The GraphQL server URL. Example: 'https://server.com:PORT/path'.
        :param headers: Dict of HTTP Headers.
        :param cookies: Dict of HTTP cookies.
        :param auth: BasicAuth object to enable Basic HTTP auth if needed
                     Or Appsync Authentication class
        :param ssl: ssl_context of the connection. Use ssl=False to disable encryption
        :param ssl_close_timeout: Timeout in seconds to wait for the ssl connection
                                  to close properly
        :param json_serialize: Json serializer callable.
                By default json.dumps() function
        :param client_session_args: Dict of extra args passed to
                `aiohttp.ClientSession`_

        .. _aiohttp.ClientSession:
          https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession
        N)
r    r!   r"   r#   r$   r%   r&   r(   sessionr'   )
selfr    r!   r"   r#   r$   r%   r&   r'   r(    r,   l/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/gql/transport/aiohttp.py__init__+   s   
zAIOHTTPTransport.__init__c                    s   | j du r@| j| jt| jtrdn| j| jd}| jdur'tj	| jd|d< | j
r0|| j
 td tjdi || _ dS td)aE  Coroutine which will create an aiohttp ClientSession() as self.session.

        Don't call this coroutine directly on the transport, instead use
        :code:`async with` on the client and this coroutine will be executed
        to create the session.

        Should be cleaned with a call to the close coroutine.
        N)r"   r!   r#   r'   )totalr%   zConnecting transportzTransport is already connectedr,   )r*   r"   r!   
isinstancer#   r   r'   r%   aiohttpClientTimeoutr(   updatelogdebugClientSessionr   )r+   r(   r,   r,   r-   connectU   s$   



	

zAIOHTTPTransport.connectc           	         s   dt    fdd}dd }| jj D ]/}|D ]*\}}t|jdd}|du r+qd7 |j}|j}t	j
||d	|_t	j
||d
|_qqdkrO    S )a  Work around aiohttp issue that doesn't properly close transports on exit.

        See https://github.com/aio-libs/aiohttp/issues/1925#issuecomment-639080209

        Returns:
           An event that will be set once all transports have been properly closed.
        r   c                    sH   z||  W d8 dkr    d S d S d8 dkr#    w w )Nr   r   )set)exc	orig_lostall_is_lostssl_transportsr,   r-   connection_lost   s   

zEAIOHTTPTransport.create_aiohttp_closed_event.<locals>.connection_lostc                 S   s"   z|   W d S  t y   Y d S w )N)AttributeErrororig_eof_receivedr,   r,   r-   eof_received   s
   zBAIOHTTPTransport.create_aiohttp_closed_event.<locals>.eof_received_ssl_protocolNr   )r:   r@   )asyncioEvent	connector_connsvaluesgetattr	transportr>   rB   	functoolspartialr8   )	r*   r>   rB   connhandler_protor:   rA   r,   r;   r-   create_aiohttp_closed_eventz   s,   


z,AIOHTTPTransport.create_aiohttp_closed_eventc                    s   | j durCtd | jr| jddu rtd n'| | j }| j  I dH  zt|	 | j
I dH  W n
 tjyB   Y nw d| _ dS )a   Coroutine which will close the aiohttp session.

        Don't call this coroutine directly on the transport, instead use
        :code:`async with` on the client and this coroutine will be executed
        when you exit the async context manager.
        NzClosing transportconnector_ownerFz1connector_owner is False -> not closing connector)r*   r4   r5   r(   getrQ   closerD   wait_forwaitr&   TimeoutError)r+   closed_eventr,   r,   r-   rT      s   


zAIOHTTPTransport.closedocumentvariable_valuesoperation_name
extra_argsupload_filesc              	      s  t |}d|i}|r||d< |r|dusJ t|| jd\} ||d< t }	dd t D }
 fddt D }| |}td	| |	j	d
|dd | |
}td| |	j	d|dd |
 D ]\}}t|d|}t|dd}|	j	||||d qfd|	i}n|r||d< ttjrtd| | d|i}|r|| t| jtr| j| |ddi|d< | jdu rtd| jj| jfd| ji|4 I dH z}|j| _dtjdtfdd}z|jddI dH }ttjr| I dH }td| W n t y   ||dI dH  Y nw |du r"||dI dH  d|vr4d|vr4||d I dH  t!|"d|"d|"d!d"W  d  I dH  S 1 I dH sUw   Y  dS )#a  Execute the provided document AST against the configured remote server
        using the current session.
        This uses the aiohttp library to perform a HTTP POST request asynchronously
        to the remote server.

        Don't call this coroutine directly on the transport, instead use
        :code:`execute` on a client or a session.

        :param document: the parsed GraphQL request
        :param variable_values: An optional Dict of variable values
        :param operation_name: An optional Operation name for the request
        :param extra_args: additional arguments to send to the aiohttp post method
        :param upload_files: Set to True if you want to put files in the variable values
        :returns: an ExecutionResult object.
        queryoperationNameN)	variablesr   r`   c                 S   s   i | ]
\}}t ||gqS r,   str.0ipathr,   r,   r-   
<dictcomp>  s    z,AIOHTTPTransport.execute.<locals>.<dictcomp>c                    s   i | ]\}}t | | qS r,   ra   rc   filesr,   r-   rg     s    zoperations %s
operationszapplication/json)content_typezfile_map %smapnamerk   )filenamerk   dataz>>> %sjsonzcontent-typer!   zTransport is not connectedr$   respreasonc              
      s\   z|    W n ty } z	tt||j|d }~ww |  I d H }td| d| )Nz(Server did not return a GraphQL result: z: )raise_for_statusr   r   rb   statustextr   )rq   rr   eresult_textr,   r,   r-   raise_response_error9  s   z6AIOHTTPTransport.execute.<locals>.raise_response_errorz<<< %szNot a JSON answererrorsz$No "data" or "errors" keys in answer
extensions)ry   ro   rz   )#r   r   r   r1   FormData	enumerater'   r4   r5   	add_fielditemsrI   isEnabledForloggingINFOinfor3   r0   r#   r   get_headersr*   r   postr    r$   r!   response_headersClientResponserb   rp   ru   	Exceptionr   rS   )r+   rY   rZ   r[   r\   r]   	query_strpayloadnulled_variable_valuesro   file_mapfile_streamsoperations_strfile_map_strkfrm   rk   	post_argsrq   rx   resultrw   r,   rh   r-   execute   s   





&
2zAIOHTTPTransport.executec                 C   s   t d)zDSubscribe is not supported on HTTP.

        :meta private:
        z2 The HTTP transport does not support subscriptions)NotImplementedError)r+   rY   rZ   r[   r,   r,   r-   	subscribe`  s   
zAIOHTTPTransport.subscribe)r)   N)NNNF)NN)(__name__
__module____qualname____doc__ioIOBaser1   StreamReaderr   r   r   r	   r   __annotations__rp   dumpsrb   r   r   r   r
   r   r   boolr   intfloatr   r   r.   r7   staticmethodrD   rE   rQ   rT   r   r   r   r   r,   r,   r,   r-   r      s   
 		


*%
4
 
r   )/rD   rK   r   rp   r   r$   r   typingr   r   r   r   r   r   r	   r
   r1   aiohttp.client_exceptionsr   aiohttp.client_reqrepr   aiohttp.helpersr   aiohttp.typedefsr   r   graphqlr   r   r   	multidictr   utilsr   appsync_authr   async_transportr   
exceptionsr   r   r   r   	getLoggerr   r4   r   r,   r,   r,   r-   <module>   s(    (
