
    %ha                     T    S SK Jr  S SKJr  S SKJrJr   " S S5      r " S S5      rg)	    )BytesIO)SpooledTemporaryFile)AsyncToSyncsync_to_asyncc                   $    \ rS rSrSrS rS rSrg)
WsgiToAsgi   z?
Wraps a WSGI application to make it into an ASGI application.
c                     Xl         g Nwsgi_applicationselfr   s     >/var/www/html/env/lib/python3.13/site-packages/asgiref/wsgi.py__init__WsgiToAsgi.__init__   s     0    c                 X   #    [        U R                  5      " XU5      I Sh  vN   g N7f)z
ASGI application instantiation point.
We return a new WsgiToAsgiInstance here with the WSGI app
and the scope, ready to respond when it is __call__ed.
N)WsgiToAsgiInstancer   )r   scopereceivesends       r   __call__WsgiToAsgi.__call__   s"      !!6!67MMMs    *(*r   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r   r   r   r      s    1Nr   r   c                   D    \ rS rSrSrS rS rS rS
S jr\	S 5       r
S	rg)r      z3
Per-socket instance of a wrapped WSGI application
c                 ,    Xl         SU l        S U l        g )NF)r   response_startedresponse_content_lengthr   s     r   r   WsgiToAsgiInstance.__init__   s     0 %'+$r   c                   #    US   S:w  a  [        S5      eXl        [        SS9 n U" 5       I S h  vN nUS   S:w  a  [        S5      eUR                  UR	                  SS	5      5        UR	                  S
5      (       d  OM]  UR                  S5        [        U5      U l        U R                  U5      I S h  vN   S S S 5        g  N N! , (       d  f       g = f7f)Ntypehttpz&WSGI wrapper received a non-HTTP scopei   )max_sizezhttp.requestz0WSGI wrapper received a non-HTTP-request messagebodyr   	more_bodyr   )	
ValueErrorr   r   writegetseekr   	sync_sendrun_wsgi_app)r   r   r   r   r,   messages         r   r   WsgiToAsgiInstance.__call__"   s     =F"EFF
!51T '	/6?n4$%WXX

7;;vs34{{;//  IIaL(.DN##D))) 21 * * 21s?   $CCCBC:C
;C?	CC
C
CCc                 0   UR                  SS5      R                  S5      R                  S5      nUS   R                  S5      R                  S5      nUR                  U5      (       a  U[	        U5      S nUS   UUUS   R                  S	5      S
US   -  SUR                  SS5      U[        5       SSSS.nSU;   a   US   S   US'   [        US   S   5      US'   O
SUS'   SUS'   UR                  S5      b  US   S   US'   U R                  R                  S/ 5       Ho  u  pgUR                  S5      nUS:X  a  SnO,US:X  a  SnO#S UR                  5       R                  S!S"5      -  nUR                  S5      nX;   a
  XX   S#-   U-   nXuU'   Mq     U$ )$z=
Builds a scope and request body into a WSGI environ object.
	root_path utf8latin1pathNmethodquery_stringasciizHTTP/%shttp_version)   r   schemer*   TF)REQUEST_METHODSCRIPT_NAME	PATH_INFOQUERY_STRINGSERVER_PROTOCOLzwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceserverr   SERVER_NAMEr@   SERVER_PORT	localhost80clientREMOTE_ADDRheaderscontent-lengthCONTENT_LENGTHzcontent-typeCONTENT_TYPEzHTTP_%s-_,)
r0   encodedecode
startswithlenr   strr   upperreplace)	r   r   r,   script_name	path_infoenvironnamevaluecorrected_names	            r   build_environ WsgiToAsgiInstance.build_environ5   s    iiR077?FFxP&M((077A	,,!#k"2"45I#Ho&"!.188A(5+@@"$yy6:"9 $!%"
 u%*8_Q%7GM"%(x);%<GM"%0GM"%)GM"99X*%*8_Q%7GM"  ::>>)R8KD;;x(D''!1'!/!*TZZ\-A-A#s-K!KLL*E(/#5=&+N# 9 r   Nc                    U R                   (       a  US   R                  US   5      e[        U S5      (       a  Uc  [        S5      eUR	                  SS5      u  pE[        U5      nU VVs/ s H5  u  pgUR                  5       R                  S5      UR                  S5      4PM7     nnnSU l        U H+  u  pgUR                  5       S:X  d  M  [        U5      U l        M-     S	UUS
.U l	        gs  snnf )z
WSGI start_response callable.
r@      response_startNz=You cannot call start_response a second time without exc_info r>   rO   zhttp.response.start)r)   statusrN   )
r%   with_tracebackhasattrr.   splitintlowerrU   r&   rf   )	r   rh   response_headersexc_infostatus_coderS   r_   r`   rN   s	            r   start_response!WsgiToAsgiInstance.start_responsef   s    
   1+,,Xa[994)**x/?O   c1-+&  0
/ ZZ\  )5<<+@A/ 	 

 (,$+KDzz|///25z, ,
 *!

s   ,<C/c                 >   U R                  U R                  U5      nSnU R                  X R                  5       H  nU R                  (       d"  SU l        U R                  U R                  5        U R                  b#  U R                  U-
  n[        U5      U:  a  USU nU R                  SUSS.5        U[        U5      -  nX0R                  :X  d  M    O   U R                  (       d"  SU l        U R                  U R                  5        U R                  SS05        g)z
Called in a subthread to run the WSGI app. We encapsulate like
this so that the start_response callable is called in the same thread.
r   TNzhttp.response.body)r)   r,   r-   r)   )	rb   r   r   rq   r%   r2   rf   r&   rX   )r   r,   r^   
bytes_sentoutputbytes_alloweds         r   r3   WsgiToAsgiInstance.run_wsgi_app   s     $$TZZ6
++G5H5HIF(((,%t223++7 $ < <z Iv;.#N]3FNN-vDQ #f+%J999# J& $$$(D!NN4../ 456r   )r&   rf   r%   r   r2   r   r   )r   r   r   r   r   r   r   rb   rq   r   r3   r    r!   r   r   r   r      s1    ,
*&/b
@ 7 7r   r   N)	ior   tempfiler   asgiref.syncr   r   r   r   r!   r   r   <module>r{      s&     ) 3N N"N7 N7r   