o
    lf                     @   sP   d dl mZ d dlmZ d dlmZ d dlmZmZ edZ	G dd deZ
dS )	    )patch_vary_headers)MiddlewareMixin)_lazy_re_compile)compress_sequencecompress_stringz\bgzip\bc                   @   s   e Zd ZdZdZdd ZdS )GZipMiddlewarez
    Compress content if the browser allows gzip compression.
    Set the Vary header accordingly, so that caches will base their storage
    on the Accept-Encoding header.
    d   c                    s  |j st|jdk r|S |dr|S t|d |jdd}t|s&|S |j rI|j	r;|j
  fdd}| |_
n	t|j
jd|_
|jd	= n t|jjd}t|t|jkr\|S ||_tt|j|jd	< |d
}|r||dr|d| |jd
< d|jd< |S )N   zContent-Encoding)zAccept-EncodingHTTP_ACCEPT_ENCODING c                    s*    2 z3 d H W } t | jdV  q6 d S )Nmax_random_bytes)r   r   )chunkorignal_iteratorself Z/var/www/ticemtrilhas/avaliacao_env/lib/python3.10/site-packages/django/middleware/gzip.pygzip_wrapper'   s   
z5GZipMiddleware.process_response.<locals>.gzip_wrapperr   zContent-LengthETag"zW/gzip)	streaminglencontent
has_headerr   METAgetre_accepts_gzipsearchis_asyncstreaming_contentr   r   headersr   str
startswith)r   requestresponseaer   compressed_contentetagr   r   r   process_response   s>   






zGZipMiddleware.process_responseN)__name__
__module____qualname____doc__r   r*   r   r   r   r   r   	   s    r   N)django.utils.cacher   django.utils.deprecationr   django.utils.regex_helperr   django.utils.textr   r   r   r   r   r   r   r   <module>   s    