U
    R+|j�  ã                   @   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 |¡sL|S |j r’|j	rv|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-EncodingZ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©Zorignal_iteratorÚself© ú^c:\users\snmko\desktop\web_content\django_cbt\venv\Lib\site-packages\django/middleware/gzip.pyÚgzip_wrapper'   s
    þz5GZipMiddleware.process_response.<locals>.gzip_wrapperr   zContent-LengthÚETagú"zW/Úgzip)Z	streamingÚlenÚcontentÚ
has_headerr   ZMETAÚgetÚre_accepts_gzipÚsearchZis_asyncZstreaming_contentr   r   Úheadersr   ÚstrÚ
startswith)r   ÚrequestÚresponseZaer   Z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)Zdjango.utils.cacher   Zdjango.utils.deprecationr   Zdjango.utils.regex_helperr   Zdjango.utils.textr   r   r   r   r   r   r   r   Ú<module>   s
   