
    i                        d Z 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
 e
j        j        Zdddddej        dej        dee	j        ej                          dedz  d	edz  d
edz  ddfdZdej        dej        dej        dedz  d	edz  d
edz  ddfdZdej        dej        dej        dedz  d	edz  d
edz  ddfdZdefdZdej        dej        dej        fdZdS )zFlask integration for Inngest.    N)
client_libcomm_lib
config_libconstfunction
server_libpublic_pathserve_origin
serve_pathappclient	functionsr
   r   r   returnc                    t          j        |t          |t          j        j                  }t          d |D                       }|rt          | |||||           dS t          | |||||           dS )a>  
    Serve Inngest functions in a Flask app.

    Args:
    ----
        app: Flask app.
        client: Inngest client.
        functions: List of functions to serve.
        public_path: Path that the Inngest server sends requests to. This is only necessary if the SDK is behind a proxy that rewrites the path.
        serve_origin: Origin for serving Inngest functions. This is typically only useful during Docker-based development.
        serve_path: Path for serving Inngest functions. This is only useful if you don't want serve Inngest at the /api/inngest path.
    )r   	frameworkr   	streamingc              3   2   K   | ]}|j         p|j        V  d S )N)is_handler_asyncis_on_failure_handler_async).0r   s     J/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/flask.py	<genexpr>zserve.<locals>.<genexpr>1   sA         	!IX%I         r	   N)	r   CommHandler	FRAMEWORKr   	StreamingDISABLEany_create_handler_async_create_handler_sync)r   r   r   r
   r   r   handler
async_modes           r   server$      s    , "/)	  G   !    J  
#%!	
 	
 	
 	
 	
 	
 	#%!	
 	
 	
 	
 	
 	
r   r"   c                    |                      t          j                  pt          j        g d          dt
          j        t          z  ffd            }d S )NGETPOSTPUTmethodsr   c            
      p  K   t          j        t                      t          t          j        j                                                  t          j        j        t          j        t          j        j	                  } t          j        j
        dk    r#t                              |                     S t          j        j
        dk    r)t                              |            d {V           S t          j        j
        dk    r)t                              |            d {V           S dS N)bodyheadersr
   query_paramsraw_requestrequest_urlr   r   r'   r(   r)    )r   CommRequest_get_body_bytesdictflaskrequestr/   itemsargsurlmethod_to_responseget_syncpostputcomm_reqr   r"   r
   r   r   s    r   inngest_apiz*_create_handler_async.<locals>.inngest_apiR   s2     
 ' "".446677#+)%!	
 	
 	
 =5((  **  
 =6))ll8,,,,,,,,  
 =5((kk(++++++++   rr   router   get_serve_pathr   DEFAULT_SERVE_PATHr7   Responsestrr   r   r"   r
   r   r   rC   s    ````` r   r    r    I   s     	YY!*--I1I&&&   u~3         	   r   c                    |                      t          j                  pt          j        g d          dt
          j        t          z  ffd            }d S )Nr&   r*   r   c            
      T   t          j        t                      t          t          j        j                                                  t          j        j        t          j        t          j        j	                  } t          j        j
        dk    r#t                              |                     S t          j        j
        dk    r#t                              |                     S t          j        j
        dk    r#t                              |                     S dS r-   )r   r4   r5   r6   r7   r8   r/   r9   r:   r;   r<   r=   r>   	post_syncput_syncrA   s    r   rC   z)_create_handler_sync.<locals>.inngest_api   s   
 ' "".446677#+)%!	
 	
 	
 =5((  **  
 =6))!!(++  
 =5((  **   rr   rD   rJ   s    ````` r   r!   r!   x   s     	YY!*--I1I&&&   #-         	   r   c                  d    t           j                            d           t           j        j        S )NT)as_text)r7   r8   get_datadata r   r   r5   r5      s&    	M4(((=r   comm_resc                 8   |                                 }t          |t                    rQt          j                            | j        |          }t          j        |j	                  
                    d          }t          j        |j        ||j                  S )Nzutf-8)r/   responsestatus)
body_bytes
isinstance	Exceptionr   CommResponse
from_errorloggerjsondumpsr.   encoder7   rH   r/   status_code)r   rT   r.   s      r   r=   r=      s       D$	"" 9(33FM4HHz(-((//88> #   r   )__doc__r^   typingr7   inngest._internalr   r   r   r   r   r   	FrameworkFLASKr   FlaskInngestlistFunctionAnyrI   r$   r   r    r!   bytesr5   r[   rH   r=   rS   r   r   <module>rm      s@   $ $                    &	 ##!2
 2
 2
	2
2
 H%fj122

 t2
 *2
 d
2
 
2
 2
 2
 2
j,	,, !,
 t, *, d
, 
, , , ,^,	,, !,
 t, *, d
, 
, , , ,^    
# ^     r   