
    Ngq6                        U d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ dZ,erddl-m.Z. eee/ged         f                  Z0 e1ej2        3                    d                    Z4ee1         e5d<    e            Z6ee         e5d<    e
d dD                       Z7dZ8 e
dddddd          Z9e6j:        ;                                 e9<                                D ]\  Z=Z>e6?                    e=e>            G d de+          Z@dS )    N)suppress)	MimeTypes)S_ISREG)MappingProxyType)IOTYPE_CHECKINGAny	AwaitableCallableFinalIteratorListOptionalTupleUnioncast   )hdrs)AbstractStreamWriter)ETAG_ANYETagmust_be_empty_body)LooseHeadersPathLike)HTTPForbiddenHTTPNotFoundHTTPNotModifiedHTTPPartialContentHTTPPreconditionFailedHTTPRequestRangeNotSatisfiable)StreamResponse)FileResponse)BaseRequestAIOHTTP_NOSENDFILE
NOSENDFILECONTENT_TYPESc                 4    i | ]}|t           j        |         S  )r&   encodings_map).0exts     T/var/www/html/ai-engine/env/lib/python3.11/site-packages/aiohttp/web_fileresponse.py
<dictcomp>r-   4   s"    EEEsS-
%c
*EEE    ).br.gzzapplication/octet-streamr0   r/   z.bz2z.Zz.xz)zapplication/gzipzapplication/x-brotlizapplication/x-bzip2zapplication/x-compresszapplication/x-xzc                       e Zd ZdZ	 	 	 	 d dedededee         d	ee         d
df fdZ	de
e         deded
efdZdede
e         deded
ef
dZddde
e         deded
ef
 fdZededeedf         ded
efd            Zdddeded
ee         f fdZddd
ee         f fdZded
eej        ej        ee         f         fdZddd
ee         f fdZ xZS )!r"   z,A response object can be used to send files.      Npath
chunk_sizestatusreasonheadersreturnc                     t                                          |||           t          j        |          | _        || _        d S )N)r6   r7   r8   )super__init__pathlibPath_path_chunk_size)selfr4   r5   r6   r7   r8   	__class__s         r,   r<   zFileResponse.__init__N   sC     	vwGGG\$''
%r.   fobjoffsetc                 V    |                     |           |                    |          S N)seekread)rA   rC   rD   r5   s       r,   _seek_and_readzFileResponse._seek_and_read[   s&    		&yy$$$r.   writercountc                 p  K   | j         }t          j                    }|                    d | j        |||           d {V }|rY|                    |           d {V  ||z
  }|dk    rn2|                    d |j        t          ||                     d {V }|Y|                                 d {V  |S Nr   )	r@   asyncioget_event_looprun_in_executorrI   writerH   mindrain)rA   rJ   rC   rD   rK   r5   loopchunks           r,   _sendfile_fallbackzFileResponse._sendfile_fallback_   s      %
%''**$%tVZ
 
 
 
 
 
 
 
  	X,,u%%%%%%%%%J&Ezz..tTYJPU@V@VWWWWWWWWE  	X llnnr.   requestr#   c                   K   t                                          |           d {V }|J t          s| j        r|                     ||||           d {V S |j        }|j        }|J 	 |                    ||||           d {V  n.# t          $ r! |                     ||||           d {V cY S w xY wt                      	                                 d {V  |S rF   )
r;   preparer%   compressionrV   _loop	transportsendfileNotImplementedError	write_eof)	rA   rW   rC   rD   rK   rJ   rT   r\   rB   s	           r,   	_sendfilezFileResponse._sendfilet   sJ      www////////!!! 	N) 	N00vuMMMMMMMMM}%	$$$	N--	4??????????" 	N 	N 	N00vuMMMMMMMMMMM	N gg!!!!!!!!!s   .B (B87B8
etag_valueetags.weakc                     t          |          dk    r|d         j        t          k    rdS t           fd|D                       S )Nr   r   Tc              3   @   K   | ]}s|j         |j        k    V  d S rF   )is_weakvalue)r*   etagra   rc   s     r,   	<genexpr>z+FileResponse._etag_match.<locals>.<genexpr>   sM       
 
)-$
FJl
J*$
 
 
 
 
 
r.   )lenrg   r   any)ra   rb   rc   s   ` `r,   _etag_matchzFileResponse._etag_match   se    u::??uQx~994 
 
 
 
 
16
 
 
 
 
 	
r.   last_modifiedc                    K   |                      t          j                   d| _        || _        || _        t                                          |           d {V S )NF)
set_statusr   status_code_length_checkrh   rm   r;   rY   )rA   rW   ra   rm   rB   s       r,   _not_modifiedzFileResponse._not_modified   s_       	3444"	* WW__W---------r.   c                    K   |                      t          j                   d| _        t	                                          |           d {V S rM   )ro   r   rp   content_lengthr;   rY   )rA   rW   rB   s     r,   _precondition_failedz!FileResponse._precondition_failed   sO       	.:;;;WW__W---------r.   accept_encodingc                    | j         }t                                          D ]\  }}||vr
|                    |j        |z             }t          t                    5  |                                }t          |j	                  r|||fcddd           c S 	 ddd           n# 1 swxY w Y   ||
                                dfS )a  Return the file path, stat result, and encoding.

        If an uncompressed file is returned, the encoding is set to
        :py:data:`None`.

        This method should be called from a thread executor
        since it calls os.stat which may block.
        N)r?   ENCODING_EXTENSIONSitemswith_suffixsuffixr   OSErrorlstatr   st_modestat)rA   rv   	file_pathfile_extensionfile_encodingcompressed_pathsts          r,   _get_file_path_stat_encodingz)FileResponse._get_file_path_stat_encoding   s5    J	-@-F-F-H-H 		> 		>)NMO33'33I4D~4UVVO'"" > >$**,,2:&& >*B=	> > > > > > > > > >>> > > > > > > > > > > > > > > )..**D00s   -B%%B)	,B)	c                   K   t          j                    }|j                            t          j        d                                          }	 |                    d | j        |           d {V \  }}}nV# t          $ rI | 
                    t          j                   t                                          |           d {V cY S w xY wt          |j                  sF| 
                    t"          j                   t                                          |           d {V S |j        dd|j        d}|j        }|j        }	|	3|                     ||	d          s|                     |           d {V S |j        }
|
:|	8|j        |
                                k    r|                     |           d {V S |j        }|5|                     ||d          r|                     |||           d {V S |j        }|<|:|j        |                                k    r|                     |||           d {V S | j        }|j        }|}d }|j        }||j        |                                k    r>	 |j        }|j         }|j!        }nm# tD          $ r` d| | j        t          j#        <   | 
                    tH          j                   t                                          |           d {V cY S w xY w|||dk     r|||z  }|dk     rd}||z
  }ntK          ||n||          |z
  }||k    r]d| | j        t          j#        <   | 
                    tH          j                   t                                          |           d {V S tL          j        }| 
                    |           t          j'        | j        vr1tP          )                    | j*                  d         ptV          | _,        |r9|| j        t          j-        <   t          j        | j        t          j.        <   d| _/        || _0        |j        | _1        || _2        d	| j        t          j3        <   ti          tj          |          }|tL          j        k    r/d
6                    |||z   dz
  |          | j        t          j#        <   |dk    sto          |j8        | j9                  r't                                          |           d {V S 	 |                    d |j:        d           d {V }nV# tv          $ rI | 
                    t"          j                   t                                          |           d {V cY S w xY w|r|}nd}	 | <                    ||||           d {V 	 t          j=        |                    d |j>                             d {V  S # t          j=        |                    d |j>                             d {V  w xY w)N x-F)rc   Tzbytes */r   byteszbytes {}-{}/{}r   rb)?rN   get_running_loopr8   getr   ACCEPT_ENCODINGlowerrP   r   r|   ro   r   rp   r;   rY   r   r~   r   st_mtime_nsst_sizest_mtimeif_matchrl   ru   if_unmodified_since	timestampif_none_matchrr   if_modified_since_statusif_range
http_rangestartstop
ValueErrorCONTENT_RANGEr    rR   r   CONTENT_TYPEr&   
guess_typer?   FALLBACK_CONTENT_TYPEcontent_typeCONTENT_ENCODINGVARY_compressionrh   rm   rt   ACCEPT_RANGESr   intformatr   methodr6   openPermissionErrorr`   shieldclose)rA   rW   rT   rv   r   r   r   ra   rm   ifmatch
unmodsinceifnonematchmodsincer6   	file_sizerK   r   ifrangerngend
real_startrC   rD   rB   s                          r,   rY   zFileResponse.prepare   s     ')) "/--d.BBGGMMOO	2151E1Ed72 2 , , , , , ,(Ir==  	2 	2 	2 OOL455511111111111		2 rz"" 	2OOM56661111111119992:999
 "t'7'7e (8 (
 (
 227;;;;;;;;;0
"j224444227;;;;;;;;; +"t'7'7$ (8 (
 (
" ++GZOOOOOOOOO, #x113333++GZOOOOOOOOOJ	"?bkW->->-@-@@@6(	h 6 6 6 4Ji3I3IT/0 > JKKK"WW__W555555555556   CO199Y&Eqyy !"%-EE 3?CC	9MMPUU  I%% 8N)7M7MDL!34OO$B$NOOO!&!9!99999999+7 '''
 DL00((44Q7P;P   	&2?DL./&*&:DL# !&D	[#+2T'(#u%%
'333/?/F/FJ.2I0 0DL+,
 A::+GNDKHH:111111111	2--dINDIIIIIIIIDD 	2 	2 	2OOM566611111111111	2  	FFF	IvuEEEEEEEEE.!5!5dDJ!G!GHHHHHHHHHH'.!5!5dDJ!G!GHHHHHHHHHHsE   &A6 6AC	C	<J A'K<;K<"T% %AU87U8W 5X
)r2   r3   NN) __name__
__module____qualname____doc__r   r   r   strr   r<   r   r	   r   rI   r   rV   r`   staticmethodr   r   boolrl   floatrr   ru   r=   r>   osstat_resultr   rY   __classcell__)rB   s   @r,   r"   r"   K   s       66
 % $*.& && & 	&
 & ,'& 
& & & & & &%2c7 %C %S %U % % % %*24S'CFOR	   *$,.sG=@IL	     * 
 
E$),< 
t 
PT 
 
 
 \
	.$	.25	.FK	.	&	'	. 	. 	. 	. 	. 	..$.	&	'. . . . . .1"1	w|R^Xc]:	;1 1 1 14nI] nIx@T7U nI nI nI nI nI nI nI nI nI nIr.   r"   )ArN   r   r=   
contextlibr   	mimetypesr   r   r   typesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   abcr   helpersr   r   r   typedefsr   r   web_exceptionsr   r   r   r   r   r    web_responser!   __all__web_requestr#   r   _T_OnChunkSentr   environr   r%   __annotations__r&   rx   r   ADDITIONAL_CONTENT_TYPESr)   clearry   r   	extensionadd_typer"   r(   r.   r,   <module>r      s/    				                    " " " " " "                                  % % % % % % 7 7 7 7 7 7 7 7 7 7 , , , , , , , ,                ) ( ( ( ( (
 )(((((( (E7IdO#;<= $rz~~.BCCDD
E$K D D D"+)++uY - - - '&EEnEEE   3  ,+! %%"&!      ! ! # # #7==?? 4 4L)<3333`I `I `I `I `I> `I `I `I `I `Ir.   