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

    Args:
    ----
        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     K/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/django.py	<genexpr>zserve.<locals>.<genexpr>6   sA         	!IX%I         r   )	r   CommHandler	FRAMEWORKr   	StreamingDISABLEany_create_handler_async_create_handler_sync)r   r   r   r   r   handler
async_modes          r   server%      s    ( "/)	  G   !    J
  
$#%!
 
 
 	
 $#%!
 
 
 	
r   r#   c                H    dt           j        j        dt           j        j        f fd}t           j                            t          t          j                  pt          j
                  t           j        j        j                            |                    S )Nrequestr   c           
      r   t          j        | j        t          | j                                                  t          | j                                                  | |                                           }| j        dk    r#t          
                    |                    S | j        dk    r#t                              |                    S | j        dk    r#t                              |                    S t          j                            ddit          j        j                  S N)bodyheadersr   query_paramsraw_requestrequest_urlr   r   GETPOSTPUTerrorzUnsupported method)status)r   CommRequestr*   dictr+   itemsr/   build_absolute_urimethod_to_responseget_sync	post_syncput_syncdjangohttpJsonResponse
HTTPStatusMETHOD_NOT_ALLOWEDr'   comm_reqr   r#   r   r   r   s     r   inngest_apiz)_create_handler_sync.<locals>.inngest_apiU   s?    '..0011#gk//11222244%!	
 	
 	
 >U""  **  
 >V##!!(++  
 >U""  **  
 {''*+?5 ( 
 
 	
r   )r=   r>   HttpRequestHttpResponseurlspath_trim_leading_slashr   get_serve_pathr   DEFAULT_SERVE_PATHviews
decoratorscsrfcsrf_exempt)r   r#   r   r   r   rD   s   ````` r   r"   r"   M   s    #
(#
		!#
 #
 #
 #
 #
 #
 #
 #
 #
 #
J ;%j11MU5M	
 	
 	$00==	  r   c                    t          j        t          j                              }t	          |t
                    r j                            |           n|dk     rt          d          dt          j        j	        dt          j        j
        f fd}t          j                            t          t          j                  pt           j                  t          j        j        j                            |                    S )N   z5Django version 5 or higher is required for async moder'   r   c           
        K   t          j        | j        t          | j                                                  t          | j                                                  | |                                           }| j        dk    r#t          
                    |                    S | j        dk    r)t                              |           d {V           S | j        dk    r)t                              |           d {V           S t          j                            ddit          j        j                  S r)   )r   r4   r*   r5   r+   r6   r/   r7   r8   r9   r:   postputr=   r>   r?   r@   rA   rB   s     r   rD   z*_create_handler_async.<locals>.inngest_api   sc      '..0011#gk//11222244%!	
 	
 	
 >U""  **  
 >V##ll8,,,,,,,,  
 >U""kk(++++++++  
 {''*+?5 ( 
 
 	
r   )r
   get_major_versionr=   get_version
isinstance	Exceptionloggerr2   r>   rE   rF   rG   rH   rI   r   rJ   r   rK   rL   rM   rN   rO   )r   r#   r   r   r   major_versionrD   s   `````  r   r!   r!      s    01C1E1EFFM-++ M****1G  #
(#
		!#
 #
 #
 #
 #
 #
 #
 #
 #
 #
J ;%j11MU5M	
 	
 	$00==	  r   comm_resc                 X   t          j        |j                  }t          |t                    r>t
          j                            | j        |          }t          j
        |j                  }t          j                            |                    d          |j        |j                  S )Nzutf-8)r+   r3   )r
   	dump_jsonr*   rW   rX   r   CommResponse
from_errorrY   jsondumpsr=   r>   rF   encoder+   status_code)r   r[   r*   s      r   r9   r9      s     ..D$	"" )(33FM4HHz(-((;##G # $   r   valuec                 ,    |                      d          S )N/)lstrip)rd   s    r   rI   rI      s    <<r   )"__doc__r>   r`   typingr=   django.httpdjango.urlsdjango.views.decorators.csrf	_internalr   r   r   r   r   r	   r
   	FrameworkDJANGOr   InngestlistFunctionAnystrrG   
URLPatternr%   r   r"   r!   r^   rF   r9   rI    r   r   <module>rw      sr                # # # #                   '	 ##!/
 /
 /
/
H%fj12/
 t	/

 */
 d
/
 [/
 /
 /
 /
d22!2 t	2
 *2 d
2 [2 2 2 2j<<!< t	<
 *< d
< [< < < <~# [    s s      r   