o
    tBh(                     @   s   d dl Z d dlZd dlZd dlmZmZ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mZmZ ddlmZ ddlmZmZ ddlmZmZmZmZ eeZG d	d
 d
Z G dd dee Z!G dd dee Z"dS )    N)
AnyAsyncGeneratorCallableDictListOptionalTupleTypeUnioncast)DocumentNodeExecutionResult	print_ast   )extract_files   )AsyncTransport	Transport)TransportAlreadyConnectedTransportClosedTransportProtocolErrorTransportServerErrorc                   @   s   e Zd ZU ejfZeee df e	d< dZ
eej e	d< ejfdeeejf def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eef fddZdeeef fddZdejdefddZdejdefddZdS )_HTTPXTransport.file_classesNresponse_headersurljson_serializec                 K   s   || _ || _|| _dS )aC  Initialize the transport with the given httpx parameters.

        :param url: The GraphQL server URL. Example: 'https://server.com:PORT/path'.
        :param json_serialize: Json serializer callable.
                By default json.dumps() function.
        :param kwargs: Extra args passed to the `httpx` client.
        N)r   r   kwargs)selfr   r   r    r   j/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/gql/transport/httpx.py__init__%   s   
z_HTTPXTransport.__init__Fdocumentvariable_valuesoperation_name
extra_argsupload_filesreturnc           	      C   s~   t |}d|i}|r||d< |r|d usJ | ||}n
|r#||d< d|i}ttjr6td| | |r=|| |S )NqueryoperationName	variablesjsonz>>> %s)	r   _prepare_file_uploadslogisEnabledForloggingDEBUGdebugr   update)	r   r"   r#   r$   r%   r&   	query_strpayload	post_argsr   r   r    _prepare_request6   s    
z _HTTPXTransport._prepare_requestc                 C   s   t || jd\}}||d< i }i }i }t| D ]0\}\}	}
t|}|	g||< ttt|
d|}t|
dd }|d u rB||
f||< q||
|f||< q| |}t	d| ||d< | |}t	d| ||d< ||d	S )
N)r*   r   r*   namecontent_typezoperations %s
operationszfile_map %smap)datafiles)
r   r   	enumerateitemsstrr   getattrr   r-   r1   )r   r#   r4   nulled_variable_valuesr<   r;   file_mapfile_streamsipathfkeyr7   r8   operations_strfile_map_strr   r   r    r,   \   s.   




z%_HTTPXTransport._prepare_file_uploadsresponsec                 C   s   |j | _ttjrtd|j z| }W n t	y&   | 
|d Y nw d|vr5d|vr5| 
|d t|d|d|ddS )Nz<<< %szNot a JSON answererrorsr;   z$No "data" or "errors" keys in answer
extensions)rK   r;   rL   )headersr   r-   r.   r/   r0   r1   textr+   	Exception_raise_response_errorr   get)r   rJ   resultr   r   r    _prepare_result   s   z_HTTPXTransport._prepare_resultreasonc              
   C   sR   z|   W n tjy } z
tt||jj|d }~ww td| d|j )Nz(Server did not return a GraphQL result: z: )	raise_for_statushttpxHTTPStatusErrorr   r?   rJ   status_coder   rN   )r   rJ   rT   er   r   r    rP      s   z%_HTTPXTransport._raise_response_errorNNNF)__name__
__module____qualname__ioIOBaser   r   r	   r   __annotations__r   r   rV   Headersr+   dumpsr
   r?   URLr   r!   r   r   boolr6   r,   Responser   rS   rP   r   r   r   r    r       s:   
 


&0r   c                   @   s|   e Zd ZU dZdZeej e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 ZdS )HTTPXTransportz:ref:`Sync Transport <sync_transports>` used to execute GraphQL queries
    on remote servers.

    The transport uses the httpx library to send HTTP POST requests.
    Nclientc                 C   s0   | j rtdtd tjdi | j| _ d S NzTransport is already connectedzConnecting transportr   )rg   r   r-   r1   rV   Clientr   r   r   r   r    connect   s   
zHTTPXTransport.connectFr"   r#   r$   r%   r&   r'   c                 C   s@   | j std| |||||}| j j| jfi |}| |S )aZ  Execute GraphQL query.

        Execute the provided document AST against the configured remote server. This
        uses the httpx library to perform a HTTP POST request to the remote server.

        :param document: GraphQL query as AST Node object.
        :param variable_values: Dictionary of input parameters (Default: None).
        :param operation_name: Name of the operation that shall be executed.
            Only required in multi-operation documents (Default: None).
        :param extra_args: additional arguments to send to the httpx post method
        :param upload_files: Set to True if you want to put files in the variable values
        :return: The result of execution.
            `data` is the result of executing the query, `errors` is null
            if no errors occurred, and is a non-empty array if an error occurred.
        Transport is not connectedrg   r   r6   postr   rS   r   r"   r#   r$   r%   r&   r5   rJ   r   r   r    execute   s   
zHTTPXTransport.executec                 C   s   | j r| j   d| _ dS dS z2Closing the transport by closing the inner sessionN)rg   closerj   r   r   r    rr      s   

zHTTPXTransport.closerZ   )r[   r\   r]   __doc__rg   r   rV   ri   r`   rk   r   r   r?   r   rd   r   rp   rr   r   r   r   r    rf      s,   
 
&rf   c                   @   s   e Zd ZU dZdZeej e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 Z		dde
deeeef  d	ee deedf fddZdS )HTTPXAsyncTransportz:ref:`Async Transport <async_transports>` used to execute GraphQL queries
    on remote servers.

    The transport uses the httpx library with anyio.
    Nrg   c                    s2   | j rtdtd tjdi | j| _ d S rh   )rg   r   r-   r1   rV   AsyncClientr   rj   r   r   r    rk      s
   
zHTTPXAsyncTransport.connectFr"   r#   r$   r%   r&   r'   c                    sH   | j std| |||||}| j j| jfi |I dH }| |S )aq  Execute GraphQL query.

        Execute the provided document AST against the configured remote server. This
        uses the httpx library to perform a HTTP POST request asynchronously to the
        remote server.

        :param document: GraphQL query as AST Node object.
        :param variable_values: Dictionary of input parameters (Default: None).
        :param operation_name: Name of the operation that shall be executed.
            Only required in multi-operation documents (Default: None).
        :param extra_args: additional arguments to send to the httpx post method
        :param upload_files: Set to True if you want to put files in the variable values
        :return: The result of execution.
            `data` is the result of executing the query, `errors` is null
            if no errors occurred, and is a non-empty array if an error occurred.
        rl   Nrm   ro   r   r   r    rp      s   
zHTTPXAsyncTransport.executec                    s&   | j r| j  I dH  d| _ dS dS rq   )rg   acloserj   r   r   r    rr   '  s
   
zHTTPXAsyncTransport.closec                 C   s   t d)zDSubscribe is not supported on HTTP.

        :meta private:
        z1The HTTP transport does not support subscriptions)NotImplementedError)r   r"   r#   r$   r   r   r    	subscribe-  s   
zHTTPXAsyncTransport.subscriberZ   )NN)r[   r\   r]   rs   rg   r   rV   ru   r`   rk   r   r   r?   r   rd   r   rp   rr   r   rx   r   r   r   r    rt      sB   
 
'	
rt   )#r^   r+   r/   typingr   r   r   r   r   r   r   r	   r
   r   rV   graphqlr   r   r   utilsr    r   r   
exceptionsr   r   r   r   	getLoggerr[   r-   r   rf   rt   r   r   r   r    <module>   s    0
 >