
    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mZ ej        j        Zdddddej        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eee         f         deeef         fdZdS )z Tornado integration for Inngest.    N)
client_libcomm_lib
config_libconstfunction
server_lib
transforms)public_pathserve_origin
serve_pathappclient	functionsr
   r   r   returnc                   t          j        t          |t          j        j                   G fddt          j        j                  }| 	                    dt          j                  pt          j        |fg           dS )aB  
    Serve Inngest functions in a Tornado app.

    Args:
    ----
        app: Tornado 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                       e Zd Zdedej        d         dz  fdZd
fdZd
fdZd
fdZ	de
j        ddf fd	ZdS )serve.<locals>.InngestHandlerchunkr   Nc                     d S N )selfr   s     L/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/tornado.pydata_receivedz+serve.<locals>.InngestHandler.data_received3   s    4    c                 \                        t          j        | j        j        t          | j        j                                                  t          | j        j	                  | j        | j        
                                                    }|                     |           d S N)bodyheadersr
   query_paramsraw_requestrequest_urlr   r   )get_syncr   CommRequestrequestr    dictr!   items_parse_query_paramsquery_argumentsfull_url_write_comm_responser   comm_reshandlerr
   r   r   s     r   getz!serve.<locals>.InngestHandler.get6       ''$* !5!;!;!=!=>> +!44" " !% $ 5 5 7 7!-)   H %%h/////r   c                 \                        t          j        | j        j        t          | j        j                                                  t          | j        j	                  | j        | j        
                                                    }|                     |           d S r   )	post_syncr   r&   r'   r    r(   r!   r)   r*   r+   r,   r-   r.   s     r   postz"serve.<locals>.InngestHandler.postH   s    (($* !5!;!;!=!=>> +!44" " !% $ 5 5 7 7!-)   H %%h/////r   c                 \                        t          j        | j        j        t          | j        j                                                  t          | j        j	                  | j        | j        
                                                    }|                     |           d S r   )put_syncr   r&   r'   r    r(   r!   r)   r*   r+   r,   r-   r.   s     r   putz!serve.<locals>.InngestHandler.putZ   r2   r   r/   c                    t          j        |j                  }t          |t                    r>t
          j                            j        |          }t          j
        |j                  }|                     |           |j                                        D ]\  }}|                     ||           |                     |j                   d S r   )r	   	dump_jsonr    
isinstance	Exceptionr   CommResponse
from_errorloggerjsondumpswriter!   r)   
add_header
set_statusstatus_code)r   r/   r    kvr   s        r   r-   z2serve.<locals>.InngestHandler._write_comm_responsel   s     '66D$	** 1#0;;FM4PPz(-00JJt (..00 & &11%%%%OOH011111r   )r   N)__name__
__module____qualname__bytestyping	Awaitabler   r1   r5   r8   r   r=   r-   )r   r0   r
   r   r   s   r   InngestHandlerr   2   s        	u 	1A$1G$1N 	 	 	 		0 	0 	0 	0 	0 	0 	0 	0 	0$	0 	0 	0 	0 	0 	0 	0 	0 	0$	0 	0 	0 	0 	0 	0 	0 	0 	0$	2+	2 	2 	2 	2 	2 	2 	2 	2 	2r   rN   z.*N)r   CommHandler	FRAMEWORKr   	StreamingDISABLEtornadowebRequestHandleradd_handlersr   get_serve_pathDEFAULT_SERVE_PATH)r   r   r   r
   r   r   rN   r0   s    ` ``` @r   serverY      s    , "/)	  GH2 H2 H2 H2 H2 H2 H2 H2 H2 H2 H23 H2 H2 H2T  )*55 ,+	
	 	 	 	 	r   rawc                 >    d |                                  D             S )Nc                 L    i | ]!\  }}||d                               d          "S )r   zutf-8)decode).0rF   rG   s      r   
<dictcomp>z'_parse_query_params.<locals>.<dictcomp>   s.    <<<1Aqt{{7##<<<r   )r)   )rZ   s    r   r*   r*      s    <<		<<<<r   )__doc__r@   rL   tornado.webrS   inngest._internalr   r   r   r   r   r   r	   	FrameworkTORNADOrP   rT   ApplicationInngestlistFunctionAnystrrY   r(   rK   r*   r   r   r   <module>rk      sn   & &                         (	 ##!p p p		 pp H%fj12p
 tp *p d
p 
p p p pf=T#tE{"23 =S#X = = = = = =r   