a
    `gx@                     @   s  U 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 d dlmZ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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l0m1Z1 dZ2er$ddl3m4Z4 eee5ged f  Z6e7ej89dZ:ee7 e;d< e Z<ee e;d< edd dD Z=dZ>eddddddZ?G dd deZ@e<jAB  e?C D ]\ZDZEe<FeDeE qeG ZHee jId  e;d < G d!d" d"e1ZJdS )#    N)suppress)Enumauto)	MimeTypes)S_ISREG)MappingProxyType)IOTYPE_CHECKINGAny	AwaitableCallableFinalIteratorListOptionalSetTupleUnioncast   )hdrs)AbstractStreamWriter)ETAG_ANYETagmust_be_empty_body)LooseHeadersPathLike)HTTPForbiddenHTTPNotFoundHTTPNotModifiedHTTPPartialContentHTTPPreconditionFailedHTTPRequestRangeNotSatisfiable)StreamResponse)FileResponse)BaseRequestZAIOHTTP_NOSENDFILE
NOSENDFILECONTENT_TYPESc                 C   s   i | ]}|t j| qS  )r'   encodings_map).0extr(   r(   f/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/aiohttp/web_fileresponse.py
<dictcomp>8       r-   ).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                   @   s(   e Zd ZdZe Ze Ze Ze ZdS )_FileResponseResultz The result of the file response.N)	__name__
__module____qualname____doc__r   	SEND_FILENOT_ACCEPTABLEPRE_CONDITION_FAILEDNOT_MODIFIEDr(   r(   r(   r,   r1   J   s
   r1   _CLOSE_FUTURESc                       sl  e Zd ZdZd'eeeee ee dd fddZ	e
e eeedd	d
Zee
e eeedddZde
e eeed fddZeeeedf eedddZdeeee d fddZdee d fddZdeeeeej ejee f dddZeeeej  ejee f dd d!Z!dee d fd"d#Z"dejejee ee d$ fd%d&Z#  Z$S )(r$   z,A response object can be used to send files.      N)path
chunk_sizestatusreasonheadersreturnc                    s(   t  j|||d t|| _|| _d S )N)r?   r@   rA   )super__init__pathlibPath_path_chunk_size)selfr=   r>   r?   r@   rA   	__class__r(   r,   rD   _   s    zFileResponse.__init__)fobjoffsetr>   rB   c                 C   s   | | ||S N)seekread)rI   rL   rM   r>   r(   r(   r,   _seek_and_readl   s    
zFileResponse._seek_and_read)writerrL   rM   countrB   c                    s~   | j }t }|d | j|||I d H }|rl||I d H  || }|dkrNql|d |jt||I d H }q(| I d H  |S Nr   )	rH   asyncioget_event_looprun_in_executorrQ   writerP   mindrain)rI   rR   rL   rM   rS   r>   loopchunkr(   r(   r,   _sendfile_fallbackp   s    
zFileResponse._sendfile_fallbackr%   )requestrL   rM   rS   rB   c              	      s   t  |I d H }|d usJ ts(| jr>| ||||I d H S |j}|j}|d usVJ z|||||I d H  W n( ty   | ||||I d H  Y S 0 t  	 I d H  |S rN   )
rC   preparer&   compressionr]   _loop	transportsendfileNotImplementedError	write_eof)rI   r^   rL   rM   rS   rR   r[   rb   rJ   r(   r,   	_sendfile   s    
zFileResponse._sendfile.)
etag_valueetagsweakrB   c                   s6   t |dkr|d jtkrdS t fdd|D S )Nr   r   Tc                 3   s"   | ]}s|j s|j kV  qd S rN   )Zis_weakvalue)r*   etagrg   ri   r(   r,   	<genexpr>   s   z+FileResponse._etag_match.<locals>.<genexpr>)lenrj   r   any)rg   rh   ri   r(   rl   r,   _etag_match   s
    zFileResponse._etag_match)r^   rg   last_modifiedrB   c                    s0   |  tj d| _|| _|| _t |I d H S )NF)
set_statusr   status_codeZ_length_checkrk   rq   rC   r_   )rI   r^   rg   rq   rJ   r(   r,   _not_modified   s
    zFileResponse._not_modified)r^   rB   c                    s$   |  tj d| _t |I d H S rT   )rr   r!   rs   content_lengthrC   r_   )rI   r^   rJ   r(   r,   _precondition_failed   s    z!FileResponse._precondition_failed)r^   accept_encodingrB   c                 C   sD  |  |\}}}|s"tjd|dfS |jdd|jd}|j }durd| j||ddsdtjd||fS |j }dur|du r|j	|
 krtjd||fS |j }	dur| j||	ddrtjd||fS |j }
dur|	du r|j	|

 krtjd||fS |d}tt t| }W d   n1 s,0    Y  tj|||fS )a  Return the response result, io object, 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x-F)ri   Trb)_get_file_path_stat_encodingr1   r7   st_mtime_nsst_sizeZif_matchrp   r8   Zif_unmodified_sincest_mtime	timestampZif_none_matchr9   Zif_modified_sinceopenr   OSErrorosstatfilenor6   )rI   r^   rw   	file_pathstfile_encodingrg   ZifmatchZ
unmodsinceZifnonematchZmodsincerL   r(   r(   r,   _make_response   s@    


.zFileResponse._make_response)rw   rB   c              	   C   s   | j }t D ]x\}}||vr q||j| }tt> | }t|j	rh|||fW  d      S W d    q1 s|0    Y  q|
 }t|j	r|nd |d fS rN   )rG   ENCODING_EXTENSIONSitemswith_suffixsuffixr   r   lstatr   st_moder   )rI   rw   r   Zfile_extensionr   Zcompressed_pathr   r(   r(   r,   r{      s    

<z)FileResponse._get_file_path_stat_encodingc              
      s  t  }|jtjd }z$|d | j||I d H \}}}}W n^ t	yp   | 
tj t |I d H  Y S  ty   | 
tj t |I d H  Y S 0 |tju r| 
tj t |I d H S |tju r| |I d H S |tju r|jdd|jd}|j}	| |||	I d H S |d us,J z<| ||||I d H W |d |j}
t|
 |
tj S |d |j}
t|
 |
tj 0 d S )N rx   ry   ) rU   get_running_looprA   getr   ACCEPT_ENCODINGlowerrW   r   PermissionErrorrr   r   rs   rC   r_   r   r   r1   r7   r8   rv   r9   r|   r}   r~   rt   _prepare_open_filecloser:   addadd_done_callbackremove)rI   r^   r[   rw   Zresponse_resultrL   r   r   rg   rq   Zclose_futurerJ   r(   r,   r_      sD    



   
zFileResponse.prepare)r^   rL   r   r   rB   c                    sF  | j }|j}|j}|}d }	|j }
d u s6||
 kr,z|j}|j}	|j}W nB ty   d| | j	t
j< | tj t |I d H  Y S 0 |	d ur,|	dk r|d u r|	|7 }	|	dk rd}	||	 }nt|d ur|n|||	 }|	|krd| | j	t
j< | tj t |I d H S tj}| | t
j| j	vrjtjdkrNtj}ntj}|| jd pft| _|r|| j	t
j< t
j| j	t
j< d| _|j dd|jd| _!|| _"|| _#d| j	t
j$< |tjkr|	}|d usJ d%||| d	 || j	t
j< |dkst&|j'|r&t |I d H S |	p.d}| (||||I d H S )
Nzbytes */r   )      Frx   ry   byteszbytes {}-{}/{}r   ))Z_statusr}   r~   Zif_ranger   Z
http_rangestartstop
ValueError_headersr   ZCONTENT_RANGErr   r"   rs   rC   r_   rY   r    ZCONTENT_TYPEsysversion_infor'   Zguess_file_type
guess_typerG   FALLBACK_CONTENT_TYPEcontent_typeZCONTENT_ENCODINGr   ZVARY_compressionr|   rk   rq   ru   ZACCEPT_RANGESformatr   methodrf   )rI   r^   rL   r   r   r?   	file_sizeZ
file_mtimerS   r   ZifrangerngendZguesserZ
real_startrM   rJ   r(   r,   r   ,  sf    








zFileResponse._prepare_open_file)r;   r<   NN)%r2   r3   r4   r5   r   intr   strr   rD   r   r
   r   rQ   r   r]   rf   staticmethodr   r   boolrp   floatrt   rv   r1   ioBufferedReaderr   stat_resultr   rE   rF   r{   r_   r   __classcell__r(   r(   rJ   r,   r$   \   sV       9/r$   )KrU   r   r   rE   r   
contextlibr   enumr   r   	mimetypesr   r   r   typesr   typingr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   abcr   helpersr   r   r   Ztypedefsr   r   Zweb_exceptionsr   r   r   r    r!   r"   Zweb_responser#   __all__Zweb_requestr%   r   Z_T_OnChunkSentr   environr   r&   __annotations__r'   r   r   ZADDITIONAL_CONTENT_TYPESr1   r)   clearr   r   	extensionadd_typesetr:   Futurer$   r(   r(   r(   r,   <module>   sP   
< 

