o
    ˳i"                     @   s   d dl Z d dlZd dlmZmZmZmZmZ d dlm	Z	 d dl
mZ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 dd	lmZ G d
d dZdS )    N)AnyDictLiteralOptionalUnion)warn)AsyncClient	HTTPErrorQueryParamsResponse)URL   )FunctionsHttpErrorFunctionsRelayError)FunctionRegionis_http_urlis_valid_str_arg)__version__c                   @   s   e Zd Z				ddededee dee dee dee ddfd	d
Z				dde
d dee deeeef  deeeef  dee defddZdeddfddZ	ddedee deeef fddZdS )AsyncFunctionsClientNurlheaderstimeoutverifyproxyhttp_clientreturnc                 C   s   t |stdt|| _dt t t dt d|| _	t
jdk r-tdtdd |d ur8td	tdd |d urCtd
tdd |d urNtdtdd |d urVt|nd| _|d urctt|nd| _|prt| j| j|ddd| _d S )Nz#url must be a valid HTTP URL stringz supabase-py/supabase_functions vpython)zX-Client-InfozX-Supabase-Client-Platformz"X-Supabase-Client-Platform-VersionzX-Supabase-Client-Runtimez!X-Supabase-Client-Runtime-Version)   
   zPython versions below 3.10 are deprecated and will not be supported in future versions. Please upgrade to Python 3.10 or newer.r   
stacklevelzVThe 'timeout' parameter is deprecated. Please configure it in the http client instead.zUThe 'verify' parameter is deprecated. Please configure it in the http client instead.zTThe 'proxy' parameter is deprecated. Please configure it in the http client instead.T<   )r   r   r   follow_redirectshttp2)r   
ValueErrorr   r   r   platformsystemreleasepython_versionr   sysversion_infor   DeprecationWarningboolr   intabsr   r   _client)selfr   r   r   r   r   r    r1   ^/home/ubuntu/.local/lib/python3.10/site-packages/supabase_functions/_async/functions_client.py__init__   sX   	

	zAsyncFunctionsClient.__init__method)GETOPTIONSHEADPOSTPUTPATCHDELETEpathjsonparamsc           
   
      s   | j j| }|pt }|| j t|tr'| jj|t||||dI d H n| jj|t||||dI d H }z|	  W |S  t
yg } zd }	t|drP|j}	t| dp_d|jj d|	|d }~ww )N)datar   r>   )r=   r   r>   status_codeerrorz9An error occurred while requesting your edge function at .)r   joinpathdictupdater   
isinstancestrr/   requestraise_for_statusr	   hasattrr@   r   r=   get)
r0   r4   r<   r   r=   r>   r   responseexcr@   r1   r1   r2   _requestL   s8   

	

zAsyncFunctionsClient._requesttokenc                 C   s   d| | j d< dS )zUpdates the authorization header

        Parameters
        ----------
        token : str
            the new jwt token sent in the authorization header
        zBearer AuthorizationN)r   )r0   rO   r1   r1   r2   set_autho   s   	zAsyncFunctionsClient.set_authfunction_nameinvoke_optionsc                    s6  t |s	td| j}t }d}d}|duri||di  |dd}|d}|rQt|ts@td| dd	d
 t|}|j	dkrQ|j	|d< |
d|j	}|d}t|tr`d|d< n	t|trid|d< | jd|g|||dI dH }|jd}	|	r|	dkrt| d|dkr| }
|
S |j}
|
S )a  Invokes a function

        Parameters
        ----------
        function_name : the name of the function to invoke
        invoke_options : object with the following properties
            `headers`: object representing the headers to send with the request
            `body`: the body of the request
            `responseType`: how the response should be parsed. The default is `json`
        z(function_name must a valid string value.Nz
text/plainr   responseTyperegionzUse FunctionRegion()r   r   anyzx-regionforceFunctionRegionbodyzContent-Typezapplication/jsonr8   )r   r=   r>   zx-relay-headertruerA   r=   )r   r$   r   r
   rE   rK   rF   r   r   valuesetrG   rD   rN   r   r=   content)r0   rR   rS   r   r>   rY   response_typerU   rL   is_relay_errorr?   r1   r1   r2   invokez   sD   







zAsyncFunctionsClient.invoke)NNNN)NNN)N)__name__
__module____qualname__rG   r   r   r-   r,   r   r3   r   listr   r
   r   rN   rQ   r   bytesr`   r1   r1   r1   r2   r      sZ    
=
#
r   )r%   r)   typingr   r   r   r   r   warningsr   httpxr   r	   r
   r   yarlr   errorsr   r   utilsr   r   r   versionr   r   r1   r1   r1   r2   <module>   s    