o
    ùT·je"  ã                   @  sÄ   U d dl mZ d dlZd dlmZ d dlZd dlZd dlm	Z	m
Z
 d dlmZmZmZmZmZ dZej d¡Zded< ddd„ZG dd„ dƒZG dd„ dƒZG dd„ deƒZddd„Zddd„ZdS )é    )ÚannotationsN)ÚNoReturn)ÚHeadersÚMutableHeaders)ÚASGIAppÚMessageÚReceiveÚScopeÚSend)zapplication/gzipzapplication/x-gzipzapplication/zipzaudio/*z	font/woffz
font/woff2z
image/avifz	image/gifz
image/jpegz	image/pngz
image/webpztext/event-streamzvideo/*Ú_gzip_capacity_limiterz,anyio.lowlevel.RunVar[anyio.CapacityLimiter]Úreturnúanyio.CapacityLimiterc                  C  s6   zt  ¡ W S  ty   t d¡} t  | ¡ |  Y S w )zDReturn the capacity limiter used for worker-thread GZip compression.é(   )r   ÚgetÚLookupErrorÚanyioÚCapacityLimiterÚset©Úlimiter© r   ú\/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/starlette/middleware/gzip.pyÚ_get_gzip_capacity_limiter    s   


ûr   c                   @  s.   e Zd Z			dedœddd„Zddd„ZdS )ÚGZipMiddlewareéô  é	   é   ©Úexclude_content_typesÚappr   Úminimum_sizeÚintÚcompresslevelÚthread_minimum_sizer   útuple[str, ...]r   ÚNonec                C  s&   || _ || _|| _|| _t|ƒ| _d S ©N)r   r    r"   r#   Ú_normalize_content_typesr   ©Úselfr   r    r"   r#   r   r   r   r   Ú__init__-   s
   	zGZipMiddleware.__init__Úscoper	   Úreceiver   Úsendr
   c                 Ã  sˆ   �|d dkr|   |||¡I d H  d S t|d�}d| dd¡v r/t| j | j| j| j| jd�}n
t| j | j| jd�}||||ƒI d H  d S )	NÚtypeÚhttp)r+   ÚgzipúAccept-EncodingÚ )r"   r#   r   r   )	r   r   r   ÚGZipResponderr    r"   r#   r   ÚIdentityResponder)r)   r+   r,   r-   ÚheadersÚ	responderr   r   r   Ú__call__<   s   €
ûzGZipMiddleware.__call__N)r   r   r   ©r   r   r    r!   r"   r!   r#   r!   r   r$   r   r%   ©r+   r	   r,   r   r-   r
   r   r%   )Ú__name__Ú
__module__Ú__qualname__ÚDEFAULT_EXCLUDED_CONTENT_TYPESr*   r7   r   r   r   r   r   ,   s    ûùr   c                   @  sD   e Zd ZU ded< edœd!dd„Zd"dd„Zd#dd„Zd$dd„Zd S )%r4   ÚstrÚcontent_encodingr   r   r   r    r!   r   r$   r   r%   c                C  s>   || _ || _t|ƒ| _t| _i | _d| _d| _d| _	d| _
d S )NF)r   r    r'   r   Úunattached_sendr-   Úinitial_messageÚstartedÚcontent_encoding_setÚcontent_type_is_excludedÚpartial_response)r)   r   r    r   r   r   r   r*   T   s   

zIdentityResponder.__init__r+   r	   r,   r   r-   r
   c                 Ã  s"   �|| _ |  ||| j¡I d H  d S r&   )r-   r   Úsend_with_compression)r)   r+   r,   r-   r   r   r   r7   e   s   €zIdentityResponder.__call__Úmessager   c                 Ã  s¾  �|d }|dkrD|| _ t| j d d�}d|v | _|d dk| _| dd	¡ d
¡d  ¡  ¡ }|| d¡d d h}| | j	¡ | _
d S |dkrj| jsQ| jsQ| j
rj| js`d| _|  | j ¡I d H  |  |¡I d H  d S |dk�r| j�sd| _| dd¡}| dd¡}t|ƒ| jk rž|sž|  | j ¡I d H  |  |¡I d H  d S |sá| j|dd�I d H }t| j d d�}| d¡ ||d krÎ| j|d< tt|ƒƒ|d< ||d< |  | j ¡I d H  |  |¡I d H  d S | j|dd�I d H }t| j d d�}| d¡ ||d k�r| j|d< |d= ||d< |  | j ¡I d H  |  |¡I d H  d S |dk�rE| dd¡}| dd¡}| j||d�I d H |d< |  |¡I d H  d S |dk�r]|  | j ¡I d H  |  |¡I d H  d S d S )Nr.   zhttp.response.startr5   )Úrawzcontent-encodingÚstatuséÎ   zcontent-typer2   ú;r   ú/z/*zhttp.response.bodyTÚbodyó    Ú	more_bodyF)rO   r1   zContent-EncodingzContent-Lengthzhttp.response.pathsend)rA   r   rC   rE   r   Ú	partitionÚstripÚlowerÚ
isdisjointr   rD   rB   r-   Úlenr    Úapply_compressionr   Úadd_vary_headerr?   r>   )r)   rG   Úmessage_typer5   Ú
media_typeÚmedia_typesrM   rO   r   r   r   rF   i   sp   €
ÿÿÿ





ýz'IdentityResponder.send_with_compressionrM   ÚbytesrO   Úboolc                Ã  s   �|S )zÊApply compression on the response body.

        If more_body is False, the compression stream is finalized. Compression
        resources are only allocated once a body is actually compressed.
        r   ©r)   rM   rO   r   r   r   rU   «   s   €z#IdentityResponder.apply_compressionN)r   r   r    r!   r   r$   r   r%   r9   )rG   r   r   r%   ©rM   rZ   rO   r[   r   rZ   )	r:   r;   r<   Ú__annotations__r=   r*   r7   rF   rU   r   r   r   r   r4   Q   s   
 û

Br4   c                      sP   e Zd ZdZ	ddedœd‡ fdd„Zeddd„ƒZddd„Zddd„Z	‡  Z
S ) r3   r0   r   r   )r#   r   r   r   r    r!   r"   r#   r   r$   r   r%   c                  s(   t ƒ j|||d� || _|| _d | _d S )Nr   )Úsuperr*   r"   r#   Ú_compressorr(   ©Ú	__class__r   r   r*   ·   s   	
zGZipResponder.__init__úzlib._Compressc                 C  s*   | j d u rt | jtjdtj ¡| _ | j S )Né   )r`   ÚzlibÚcompressobjr"   ÚDEFLATEDÚ	MAX_WBITS)r)   r   r   r   Ú
compressorÆ   s   
zGZipResponder.compressorrM   rZ   rO   r[   c                Ã  s>   �t |ƒ| jkrtƒ }tjj| j|||d�I d H S |  ||¡S )Nr   )rT   r#   r   r   Ú	to_threadÚrun_syncÚ_compress_body)r)   rM   rO   r   r   r   r   rU   Ì   s
   €zGZipResponder.apply_compressionc                 C  s4   |r| j  |¡| j  tj¡ S | j  |¡| j  ¡  S r&   )ri   ÚcompressÚflushre   ÚZ_SYNC_FLUSHr\   r   r   r   rl   Ó   s   zGZipResponder._compress_body)r   r8   )r   rc   r]   )r:   r;   r<   r?   r=   r*   Úpropertyri   rU   rl   Ú__classcell__r   r   ra   r   r3   ´   s    üù
r3   rG   r   r   c                 Ã  s
   �t dƒ‚)Nzsend awaitable not set)ÚRuntimeError)rG   r   r   r   r@   Ù   s   €r@   Úcontent_typesr$   c                 C  s   t dd„ | D ƒƒS )Nc                 s  s&   � | ]}|  d ¡d  ¡  ¡ V  qdS )rK   r   N)rP   rQ   rR   )Ú.0Úcontent_typer   r   r   Ú	<genexpr>Þ   s   €$ z+_normalize_content_types.<locals>.<genexpr>)Útuple)rs   r   r   r   r'   Ý   s   r'   )r   r   )rG   r   r   r   )rs   r$   r   r$   )Ú
__future__r   re   Útypingr   Úanyio.lowlevelr   Úanyio.to_threadÚstarlette.datastructuresr   r   Ústarlette.typesr   r   r   r	   r
   r=   ÚlowlevelÚRunVarr   r^   r   r   r4   r3   r@   r'   r   r   r   r   Ú<module>   s    
%c
%