a
     ÑOc *  ã                   @   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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 ddlmZmZ ddl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  Z&e'ej( )d¡ƒZ*ee' e+d< G dd„ de!ƒZ,dS )é    N)ÚIOÚTYPE_CHECKINGÚAnyÚ	AwaitableÚCallableÚIteratorÚListÚOptionalÚTupleÚUnionÚcasté   )Úhdrs)ÚAbstractStreamWriter)ÚETAG_ANYÚETag)ÚFinalÚLooseHeaders)ÚHTTPNotModifiedÚHTTPPartialContentÚHTTPPreconditionFailedÚHTTPRequestRangeNotSatisfiable)ÚStreamResponse)ÚFileResponse)ÚBaseRequestZAIOHTTP_NOSENDFILEÚ
NOSENDFILEc                       sæ   e Zd ZdZdeeejf eee	e e	e
 ddœ‡ f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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 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                    s6   t ƒ j|||d� t|tƒr&t |¡}|| _|| _d S )N)r    r!   r"   )ÚsuperÚ__init__Ú
isinstanceÚstrÚpathlibÚPathÚ_pathÚ_chunk_size)Úselfr   r   r    r!   r"   ©Ú	__class__© úO/var/www/html/gsl.tools/lib/python3.9/site-packages/aiohttp/web_fileresponse.pyr%   /   s
    

zFileResponse.__init__)ÚwriterÚfobjÚoffsetÚcountr#   c                 Ã   s�   | j }t ¡ }| d |j|¡I d H  | d |j|¡I d H }|r~| |¡I d H  || }|dkr`q~| d |jt||ƒ¡I d H }q:| ¡ I d H  |S ©Nr   )	r+   ÚasyncioÚget_event_loopÚrun_in_executorÚseekÚreadÚwriteÚminZdrain)r,   r1   r2   r3   r4   r   ÚloopÚchunkr/   r/   r0   Ú_sendfile_fallback?   s    zFileResponse._sendfile_fallbackr   )Úrequestr2   r3   r4   r#   c              	   ƒ   s¸   t ƒ  |¡I d H }|d usJ ‚ts2tjdk s2| jrH|  ||||¡I d H S |j}|j}|d us`J ‚z| 	||||¡I d H  W n( t
y¢   |  ||||¡I d H  Y S 0 t ƒ  ¡ I d H  |S )N)é   é   )r$   Úpreparer   ÚsysÚversion_infoÚcompressionr?   Z_loopÚ	transportÚsendfileÚNotImplementedErrorÚ	write_eof)r,   r@   r2   r3   r4   r1   r=   rG   r-   r/   r0   Ú	_sendfileU   s    zFileResponse._sendfile.)Ú
etag_valueÚetagsr#   c                    s4   t |ƒdkr|d jtkrdS t‡ fdd„|D ƒƒS )Nr   r   Tc                 3   s   | ]}|j s|jˆ kV  qd S )N)Zis_weakÚvalue)Ú.0Úetag©rL   r/   r0   Ú	<genexpr>n   ó    z2FileResponse._strong_etag_match.<locals>.<genexpr>)ÚlenrN   r   Úany)rL   rM   r/   rQ   r0   Ú_strong_etag_matchj   s    zFileResponse._strong_etag_match)r@   rL   Úlast_modifiedr#   c                 ƒ   s0   |   tj¡ d| _|| _|| _tƒ  |¡I d H S )NF)Ú
set_statusr   Ústatus_codeZ_length_checkrP   rW   r$   rC   )r,   r@   rL   rW   r-   r/   r0   Ú_not_modifiedp   s
    zFileResponse._not_modified)r@   r#   c                 ƒ   s$   |   tj¡ d| _tƒ  |¡I d H S r5   )rX   r   rY   Úcontent_lengthr$   rC   )r,   r@   r-   r/   r0   Ú_precondition_failed{   s    z!FileResponse._precondition_failedc              
   ƒ   sî  | j }d}d|j tjd¡v r>| |jd ¡}| ¡ r>|}d}t 	¡ }| 
d |j¡I d H }|jd›d|jd›�}|j}|j}	|	d ur |  ||	¡s |  |¡I d H S |j}
|
d urÔ|	d u rÔ|j|
 ¡ krÔ|  |¡I d H S |j}|d u�r|  ||¡�r|  |||¡I d H S |j}|d u�rD|d u �rD|j| ¡ k�rD|  |||¡I d H S tj| jv�rtt t|ƒ¡\}}|�snd}d}n|�r~dnd }d}| j}|j}|}d }|j}|d u �sº|j| ¡ k�rÄz|j}|j}|j}W nD t �y   d	|› �| jtj!< |  "t#j$¡ t%ƒ  &|¡I d H  Y S 0 |d u�s*|d u�rÄ|d
k �r^|d u �r^||7 }|d
k �rTd
}|| }nt'|d u�rn|n||ƒ| }||k�r´d	|› �| jtj!< |  "t#j$¡ t%ƒ  &|¡I d H S t(j$}|  "|¡ |�rÐ|| _)|�râ|| jtj*< |�rötj| jtj+< || _,|j| _-|| _.d| jtj/< t0t1|ƒ}|t(j$k�rJd 2||| d |¡| jtj!< |d
k�sn|j3tj4k�sn| j5dv �r€t%ƒ  &|¡I d H S | 
d |j6d¡I d H }|�r¢|}nd
}z,|  7||||¡I d H W | 
d |j8¡I d H  S | 
d |j8¡I d H  0 d S )NFÚgzipÚ z.gzTÚxú-zapplication/octet-streamzbytes */r   Úbyteszbytes {}-{}/{}r   )éÌ   i0  Úrb)9r*   r"   Úgetr   ÚACCEPT_ENCODINGÚ	with_nameÚnameÚis_filer6   r7   r8   ÚstatÚst_mtime_nsÚst_sizeÚst_mtimeZif_matchrV   r\   Zif_unmodified_sinceÚ	timestampZif_none_matchrZ   Zif_modified_sinceÚCONTENT_TYPEÚ	mimetypesÚ
guess_typer'   Z_statusZif_rangeZ
http_rangeÚstartÚstopÚ
ValueErrorZCONTENT_RANGErX   r   rY   r$   rC   r<   r   Úcontent_typeZCONTENT_ENCODINGZVARYrP   rW   r[   ZACCEPT_RANGESr   ÚintÚformatÚmethodZ	METH_HEADr    ÚopenrK   Úclose)r,   r@   Úfilepathr]   Z	gzip_pathr=   ÚstrL   rW   ZifmatchZ
unmodsinceZifnonematchZmodsinceÚctÚencodingZshould_set_ctr    Ú	file_sizer4   rq   ZifrangeÚrngÚendZ
real_startr2   r3   r-   r/   r0   rC   ‚   s¼    ÿþýÿþý




ÿ



ÿ$þzFileResponse.prepare)r   r   NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   r(   r)   ru   r	   r   r%   r   r   r   r?   rK   Ústaticmethodr
   r   ÚboolrV   ÚfloatrZ   r\   rC   Ú__classcell__r/   r/   r-   r0   r   ,   s8       úùþþþþr   )-r6   ro   Úosr(   rD   Útypingr   r   r   r   r   r   r   r	   r
   r   r   r^   r   Úabcr   Zhelpersr   r   Ztypedefsr   r   Zweb_exceptionsr   r   r   r   Zweb_responser   Ú__all__Zweb_requestr   ra   Z_T_OnChunkSentr†   Úenvironrd   r   Ú__annotations__r   r/   r/   r/   r0   Ú<module>   s"   
4