a
    h)                     @   s  U 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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  dd	l!m"Z" d
Z#erd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FinalIteratorListOptionalTupleUnioncast   )hdrs)AbstractStreamWriter)ETAG_ANYETagmust_be_empty_body)LooseHeadersPathLike)HTTPNotModifiedHTTPPartialContentHTTPPreconditionFailedHTTPRequestRangeNotSatisfiable)StreamResponse)FileResponse)BaseRequestZAIOHTTP_NOSENDFILE
NOSENDFILEc                       s   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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                    s(   t  j|||d t|| _|| _d S )N)r"   r#   r$   )super__init__pathlibPath_path_chunk_size)selfr    r!   r"   r#   r$   	__class__ ]/var/www/html/swiplay.fr/scambot/venv/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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 N)
r&   preparer   compressionr?   Z_loop	transportsendfileNotImplementedError	write_eof)r,   r@   r2   r3   r4   r1   r=   rD   r-   r/   r0   	_sendfileR   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 rA   )Zis_weakvalue).0etagrI   r/   r0   	<genexpr>k       z2FileResponse._strong_etag_match.<locals>.<genexpr>)lenrK   r   any)rI   rJ   r/   rN   r0   _strong_etag_matchg   s    zFileResponse._strong_etag_match)r@   rI   last_modifiedr%   c                    s0   |  tj d| _|| _|| _t |I d H S )NF)
set_statusr   status_codeZ_length_checkrM   rT   r&   rB   )r,   r@   rI   rT   r-   r/   r0   _not_modifiedm   s
    zFileResponse._not_modified)r@   r%   c                    s$   |  tj d| _t |I d H S r5   )rU   r   rV   content_lengthr&   rB   )r,   r@   r-   r/   r0   _precondition_failedx   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rz|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rd	| | jtj!< | "t#j$ t% &|I d H S t(j$}| "| |r|| _)|r|| jtj*< |rtj| jtj+< || _,|j| _-|| _.d| jtj/< t0t1|}|t(j$krJd2||| d || jtj!< |d
ksdt3|j4| j5rvt% &|I d H S |
d |j6dI d H }|r|}nd
}z2| 7||||I d H W t8|
d |j9I d H  S t8|
d |j9I d H  0 d S )NFgzip z.gzTx-zapplication/octet-streamzbytes */r   byteszbytes {}-{}/{}r   rb):r*   r$   getr   ACCEPT_ENCODING	with_namenameis_filer6   r7   r8   statst_mtime_nsst_sizest_mtimeZif_matchrS   rY   Zif_unmodified_since	timestampZif_none_matchrW   Zif_modified_sinceCONTENT_TYPE	mimetypes
guess_typestrZ_statusZif_rangeZ
http_rangestartstop
ValueErrorZCONTENT_RANGErU   r   rV   r&   rB   r<   r   content_typeZCONTENT_ENCODINGZVARYrM   rT   rX   ZACCEPT_RANGESr   intformatr   methodr"   openrH   Zshieldclose)r,   r@   filepathrZ   Z	gzip_pathr=   strI   rT   ZifmatchZ
unmodsinceZifnonematchZmodsincectencodingZshould_set_ctr"   	file_sizer4   rn   ZifrangerngendZ
real_startr2   r3   r-   r/   r0   rB      s    








zFileResponse.prepare)r   r   NN)__name__
__module____qualname____doc__r   rr   r
   rm   r   r'   r   r   r   r?   rH   staticmethodr   r   boolrS   floatrW   rY   rB   __classcell__r/   r/   r-   r0   r   ,   s8       r   ).r6   rk   osr(   typingr   r   r   r   r   r   r   r	   r
   r   r   r   r[   r   abcr   Zhelpersr   r   r   Ztypedefsr   r   Zweb_exceptionsr   r   r   r   Zweb_responser   __all__Zweb_requestr   r^   Z_T_OnChunkSentr   environr`   r   __annotations__r   r/   r/   r/   r0   <module>   s    
8