
    Q}bg["                     ^   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZ d dlmZmZmZmZmZ e j        ege j        e         f         Ze j        eege j        e         f         Z e j        d          Z G d	 d
e          Z G d d          Z G d de          ZdS )    N)ObjectReceiveStreamObjectSendStream)collapse_excgroups)BackgroundTask)ClientDisconnectRequest)ContentStreamResponseStreamingResponse)ASGIAppMessageReceiveScopeSendTc                   8     e Zd ZdZdedef fdZdefdZ xZ	S )_CachedRequesta  
    If the user calls Request.body() from their dispatch function
    we cache the entire request body in memory and pass that to downstream middlewares,
    but if they call Request.stream() then all we do is send an
    empty body so that downstream things don't hang forever.
    scopereceivec                     t                                          ||           d| _        d| _        |                                 | _        d S )NF)super__init___wrapped_rcv_disconnected_wrapped_rcv_consumedstream_wrapped_rc_stream)selfr   r   	__class__s      l/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/starlette/middleware/base.pyr   z_CachedRequest.__init__   sC    ((().&%*""&++--    returnc                    K   | j         rddiS | j        rR| j        rd| _         ddiS |                                  d {V }|d         dk    rt	          d|d                    |S t          | dd           d| _        d| j        ddS | j        rd| _        dd	ddS 	 |                                 }|	                                 d {V }| j        | _        d|| j         dS # t          $ r d| _         ddicY S w xY w)
Ntypehttp.disconnectTzUnexpected message received: _bodyzhttp.requestF)r#   body	more_bodyr    )r   r   _is_disconnectedr   RuntimeErrorgetattrr%   _stream_consumedr   	__anext__r   )r   msgr   chunks       r   wrapped_receivez_CachedRequest.wrapped_receive!   s     ) 	/ -..% 	 $ 3 26. 122 &&&&&&C6{/// ##P3v;#P#PQQQJ 4$''3)-D&&
"  
 " 	3 *.D&&"  3$..00000000-1-B**!%)%:!:  
 $ 3 3 315. 122223s   AC% %C=<C=)
__name__
__module____qualname____doc__r   r   r   r   r/   __classcell__r   s   @r   r   r      sp         0e 0g 0 0 0 0 0 0:3w :3 :3 :3 :3 :3 :3 :3 :3r    r   c                   h    e Zd Z	 ddedej        e         ddfdZdede	de
ddfd	Zd
ededefdZdS )BaseHTTPMiddlewareNappdispatchr!   c                 4    || _         || j        n|| _        d S N)r8   r9   dispatch_func)r   r8   r9   s      r   r   zBaseHTTPMiddleware.__init___   s$     .6.>T]]Hr    r   r   sendc                 <   	K   d         dk    r                      ||           d {V  d S t          |          }|j        	t          j                    dt
          dt          f 	fd}t                      5  t          j                    4 d {V  	                    ||           d {V } |	|           d {V  
                                 d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr#   httprequestr!   c                   	
K   d t          j                    \  	dt          ffdd	fd}dt          dd ffd
d
fd}                    |                               |           	 	                                 d {V }|                    dd           }|d         d	k    r|	                                 d {V }n&# t           j        $ r t          d
          w xY w|d         dk    sJ dt          j	        t          d f         f	fd}t          |d          |            |          }|d         |_        |S )Nr!   c                    K                                    rddiS t          j                    4 d {V dt          j        g t          j        t                   f         dt          ffd}                     | j                    |            d {V }d d d           d {V  n# 1 d {V swxY w Y                                    rddiS |S )Nr#   r$   funcr!   c                 ^   K    |              d {V }j                                          |S r;   )cancel_scopecancel)rC   result
task_groups     r   wrapz[BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect.<locals>.wrapz   s8      '+tvv"/66888%r    )	is_setanyiocreate_task_grouptypingCallable	Awaitabler   
start_soonwait)rI   messagerH   response_sentr/   s     @r   receive_or_disconnectzMBaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnectt   s      '')) 7"$566 244 : : : : : : :
&V=Ma=P9P)Q &VW & & & & & &
 ))$0BCCC$(D$9$9999999G: : : : : : : : : : : : : : : : : : : : : : : : : : : !'')) 7"$566s   A#B++
B58B5c                  h   K                                     d {V                                    d S r;   )rQ   close)recv_streamrS   s   r   "close_recv_stream_on_response_sentzZBaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.close_recv_stream_on_response_sent   sC      #((*********!!#####r    rR   c                 p   K   	                      |            d {V  d S # t          j        $ r Y d S w xY wr;   )r=   rK   BrokenResourceError)rR   send_streams    r   send_no_errorzEBaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.send_no_error   s]      %**7333333333330   FFs   " 55c                     K   4 d {V  	                                 d {V  n# t          $ r} | Y d } ~ nd } ~ ww xY wd d d           d {V  d S # 1 d {V swxY w Y   d S r;   )r8   	Exception)excapp_excrT   r   r   r\   r[   s    r   coroz<BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.coro   s,      ' & & & & & & & &&"hhu.C]SSSSSSSSSS$ & & &"%&& & & & & & & & & & & & & & & & & & & & & & & & & & & & & &s3   A,A
A=AAA
A"%A"infor#   http.response.debugzNo response returned.zhttp.response.startc                 
  K   4 d {V  2 3 d {V } | d         dk    sJ |                      dd          }|r|W V  |                      dd          s nK6 	 d d d           d {V  n# 1 d {V swxY w Y   d S )Nr#   zhttp.response.bodyr&   r    r'   F)get)rR   r&   r`   rW   s     r   body_streamzCBaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.body_stream   s\     & " " " " " " " ")4 " " " " " " "g&v2FFFFF&{{6377 '"&JJJJ&{{;>> "!E" *5" " " " " " " " " " " " " " " " " " " " " " " " " " " &!M '&s   A.AAA..
A8;A8status)status_codecontentrb   headers)r!   N)rK   create_memory_object_streamr   rP   r   re   EndOfStreamr)   rM   AsyncGeneratorbytes_StreamingResponseraw_headers)r@   rX   ra   rR   rb   rf   responser`   rT   rW   r\   r[   rS   r   r   rH   r/   s          @@@@@r   	call_nextz.BaseHTTPMiddleware.__call__.<locals>.call_nextn   s7     26G (-'H'J'J$K       &$ $ $ $ $ $ $W       & & & & & & & & & & & !!"DEEE!!$'''< + 3 3 5 5555555{{64006?&;;;@P$/$7$7$9$9999999G$ < < <&!M"#:;;;<
 6?&;;;;;"v'<UD['I " " " " " " " *#H-{{}}4  H $+9#5H Os   ;AC #C7)r8   r   r/   rK   Eventr   r
   r   rL   r<   set)
r   r   r   r=   r@   rr   rq   rS   rH   r/   s
   ``     @@@r   __call__zBaseHTTPMiddleware.__call__e   sB     =F""((5'4000000000F 00!1M	W M	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	^  !! 	$ 	$.00 $ $ $ $ $ $ $J!%!3!3GY!G!GGGGGGGhuot<<<<<<<<<!!###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s7   DAC3!D3
C=	=D C=	DDDr@   rr   c                 "   K   t                      r;   )NotImplementedError)r   r@   rr   s      r   r9   zBaseHTTPMiddleware.dispatch   s       "###r    r;   )r0   r1   r2   r   rM   OptionalDispatchFunctionr   r   r   r   ru   r   RequestResponseEndpointr
   r9    r    r   r7   r7   ^   s        JNM MM&,o6F&GM	M M M M\$E \$G \$4 \$D \$ \$ \$ \$|$$+B$	$ $ $ $ $ $r    r7   c                        e Zd Z	 	 	 	 	 ddededej        ej        eef                  dej        e         dej        e	         dej        ej        eej
        f                  d	df fd
Zded	df fdZ xZS )ro      Nri   rh   rj   
media_type
backgroundrb   r!   c                 `    || _         t                                          |||||           d S r;   )_infor   r   )r   ri   rh   rj   r~   r   rb   r   s          r   r   z_StreamingResponse.__init__   s2     
+w
JOOOOOr    r=   c                    K   | j         r |d| j         d           d {V  t                                          |           d {V S )Nrc   )r#   rb   )r   r   stream_response)r   r=   r   s     r   r   z"_StreamingResponse.stream_response   si      : 	L$ 5tzJJKKKKKKKKKWW,,T222222222r    )r}   NNNN)r0   r1   r2   r	   intrM   rx   Mappingstrr   Anyr   r   r   r4   r5   s   @r   ro   ro      s        =A+/6:AE
P 
P
P 
P S!9:	
P
 OC(
P ON3
P ofnS&*_=>
P 

P 
P 
P 
P 
P 
P3$ 34 3 3 3 3 3 3 3 3 3 3r    ro   )rM   rK   	anyio.abcr   r   starlette._utilsr   starlette.backgroundr   starlette.requestsr   r   starlette.responsesr	   r
   r   starlette.typesr   r   r   r   r   rN   rO   rz   ry   TypeVarr   r   r7   ro   r{   r    r   <module>r      s     ; ; ; ; ; ; ; ; / / / / / / / / / / / / 8 8 8 8 8 8 8 8 J J J J J J J J J J B B B B B B B B B B B B B B /7)V5Eh5O*OP ?%&(8(BB  FN3H3 H3 H3 H3 H3W H3 H3 H3Vh$ h$ h$ h$ h$ h$ h$ h$V3 3 3 3 3* 3 3 3 3 3r    