o
    /h                     @   s^   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 G dd dZdS )	    )AnyDictLiteralOptionalUnion)	HTTPErrorResponse   )FunctionsHttpErrorFunctionsRelayError)
SyncClient__version__c                   @   s   e Zd ZddedededefddZ		dd	ed
 dede	eeef d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 )SyncFunctionsClientTurlheaderstimeoutverifyc                 C   s<   || _ ddt i|| _t| j | jt||ddd| _d S )Nz
User-Agentzsupabase-py/functions-py vT)base_urlr   r   r   follow_redirectshttp2)r   r   r   r   bool_client)selfr   r   r   r    r   X/var/www/html/govbot/env/lib/python3.10/site-packages/supafunc/_sync/functions_client.py__init__
   s   
zSyncFunctionsClient.__init__N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   r.   r   r   r   set_auth+   s   	zSyncFunctionsClient.set_authfunction_nameinvoke_optionsc           
      C   s   | j }d}d}|durJ||di  |dd}|d}|r2t|tr2|dkr2|  |d< |d}t|trAd|d	< n	t|trJd
|d	< | jd| j	 d| ||d}|j d}|rn|dkrnt
| d|dkrx| }	|	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`
        Nz
text/plainr   responseTyperegionanyzx-regionbodyzContent-Typezapplication/jsonr    /)r   r$   zx-relay-headertruer&   r$   )r   updater*   
isinstancestrlowerstripdictr-   r   r   r$   content)
r   r1   r2   r   r6   response_typer4   r+   is_relay_errordatar   r   r   invoke6   s2   




zSyncFunctionsClient.invoke)T)NN)N)__name__
__module____qualname__r;   r   intr   r   r   r   r   r   r   r-   r0   bytesrC   r   r   r   r   r   	   s0    

r   N)typingr   r   r   r   r   httpxr   r   errorsr
   r   utilsr   r   r   r   r   r   r   <module>   s
    