o
    `gh                     @   sn   d dl mZmZmZmZmZ d dlmZ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 )
    )AnyDictLiteralOptionalUnion)	HTTPErrorResponse   )FunctionsHttpErrorFunctionsRelayError)
SyncClientis_http_urlis_valid_str_arg)__version__c                   @   s   e Zd Z		ddededededee f
dd	Z		dd
e	d dedeeeef  deee
e
f  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 )SyncFunctionsClientTNurlheaderstimeoutverifyproxyc              	   C   sV   t |std || _ddt i|| _t| j| jt|tt||ddd| _	d S )Nz#url must be a valid HTTP URL stringz
User-Agentzsupabase-py/functions-py vT)base_urlr   r   r   r   follow_redirectshttp2)
r   
ValueErrorr   r   r   r   boolintabs_client)selfr   r   r   r   r    r   Z/var/www/html/propose/venv/lib/python3.10/site-packages/supafunc/_sync/functions_client.py__init__   s    

zSyncFunctionsClient.__init__method)GETOPTIONSHEADPOSTPUTPATCHDELETEjsonreturnc              
   C   s`   | j j||||d}z|  W |S  ty/ } zt| dp(d|jjd|d }~ww )N)r*   r   errorz9An error occurred while requesting your edge function at .)r   requestraise_for_statusr   r
   r*   getr   )r   r"   r   r   r*   responseexcr   r   r    _request$   s   
zSyncFunctionsClient._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   )r   r4   r   r   r    set_auth6   s   	zSyncFunctionsClient.set_authfunction_nameinvoke_optionsc           
      C   s
  t |std| j}d}d}|durR||di  |dd}|d}|r:t|tr:|dkr:|  |d< |d	}t|trId|d
< n	t|t	rRd|d
< | j
d| j d| ||d}|jd}|rv|dkrvt| 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regionanyzx-regionbodyzContent-Typezapplication/jsonr&   /)r   r*   zx-relay-headertruer,   r*   )r   r   r   updater0   
isinstancestrlowerstripdictr3   r   r   r*   content)
r   r7   r8   r   r<   response_typer:   r1   is_relay_errordatar   r   r    invokeA   s6   




zSyncFunctionsClient.invoke)TN)NN)N)__name__
__module____qualname__rA   r   r   r   r   r!   r   r   r   r3   r6   r   bytesrI   r   r   r   r    r   
   sH    


r   N)typingr   r   r   r   r   httpxr   r   errorsr
   r   utilsr   r   r   versionr   r   r   r   r   r    <module>   s    