Ë
    ¦#ijÇ$  ã                   ó¨   — d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ  G d„ d	e«      Z G d
„ de«      Z G d„ dee«      Zy)ai  
Cache middleware. If enabled, each Django-powered page will be cached based on
URL. The canonical way to enable cache middleware is to set
``UpdateCacheMiddleware`` as your first piece of middleware, and
``FetchFromCacheMiddleware`` as the last::

    MIDDLEWARE = [
        'django.middleware.cache.UpdateCacheMiddleware',
        ...
        'django.middleware.cache.FetchFromCacheMiddleware'
    ]

This is counterintuitive, but correct: ``UpdateCacheMiddleware`` needs to run
last during the response phase, which processes middleware bottom-up;
``FetchFromCacheMiddleware`` needs to run last during the request phase, which
processes middleware top-down.

The single-class ``CacheMiddleware`` can be used for some simple sites.
However, if any other piece of middleware needs to affect the cache key, you'll
need to use the two-part ``UpdateCacheMiddleware`` and
``FetchFromCacheMiddleware``. This'll most often happen when you're using
Django's ``LocaleMiddleware``.

More details about how the caching works:

* Only GET or HEAD-requests with status code 200 are cached.

* The number of seconds each page is stored for is set by the "max-age" section
  of the response's "Cache-Control" header, falling back to the
  CACHE_MIDDLEWARE_SECONDS setting if the section was not found.

* This middleware expects that a HEAD request is answered with the same
  response headers exactly like the corresponding GET request.

* When a hit occurs, a shallow copy of the original response object is returned
  from process_request.

* Pages will be cached based on the contents of the request headers listed in
  the response's "Vary" header.

* This middleware also sets ETag, Last-Modified, Expires and Cache-Control
  headers on the response object.

* If the request had an Authorization header and the response was not marked
  "Cache-Control: public", the response will vary on Authorization.
é    N)Úsettings)ÚDEFAULT_CACHE_ALIASÚcaches)Úget_cache_keyÚget_max_ageÚhas_vary_headerÚlearn_cache_keyÚpatch_response_headersÚpatch_vary_headers)ÚMiddlewareMixin)Úparse_http_date_safec                   ó>   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zd„ Zˆ xZ	S )ÚUpdateCacheMiddlewarea6  
    Response-phase cache middleware that updates the cache if the response is
    cacheable.

    Must be used as part of the two-part update/fetch cache middleware.
    UpdateCacheMiddleware must be the first piece of middleware in MIDDLEWARE
    so that it'll get called last during the response phase.
    c                 ó°   •— t         ‰| �  |«       t        j                  | _        d | _        t        j                  | _        t        j                  | _	        y ©N)
ÚsuperÚ__init__r   ÚCACHE_MIDDLEWARE_SECONDSÚcache_timeoutÚpage_timeoutÚCACHE_MIDDLEWARE_KEY_PREFIXÚ
key_prefixÚCACHE_MIDDLEWARE_ALIASÚcache_alias©ÚselfÚget_responseÚ	__class__s     €úQ/var/www/html/office/venv/lib/python3.12/site-packages/django/middleware/cache.pyr   zUpdateCacheMiddleware.__init__J   sA   ø€ Ü‰Ñ˜Ô&Ü%×>Ñ>ˆÔØ ˆÔÜ"×>Ñ>ˆŒÜ#×:Ñ:ˆÕó    c                 ó(   — t         | j                     S r   ©r   r   ©r   s    r   ÚcachezUpdateCacheMiddleware.cacheQ   ó   € ä�d×&Ñ&Ñ'Ð'r    c                 ó6   — t        |d«      xr |j                  S )NÚ_cache_update_cache)Úhasattrr'   )r   ÚrequestÚresponses      r   Ú_should_update_cachez*UpdateCacheMiddleware._should_update_cacheU   s   € Ü�wÐ 5Ó6ÒV¸7×;VÑ;VÐVr    c                 ó  ‡ ‡‡‡— ‰ j                  ||«      s|S |j                  s|j                  dvr|S |j                  rt	        |d«      r|S |j                  dd«      j                  «       Š‰rt        ˆfd„dD «       «      r|S t	        |d«      r|S ‰ j                  Š‰€!t        |«      Š‰€‰ j                  Šn‰dk(  r|S t        |‰«       |j                  j                  d	«      rd
‰vrt        |d«       ‰r‰|j                  dk(  rzt        ||‰‰ j                  ‰ j                   ¬«      Št#        |d«      r-t%        |j&                  «      r|j)                  ˆˆ ˆfd„«       |S ‰ j                   j+                  ‰|‰«       |S )zSet the cache, if needed.)éÈ   i0  ÚCookiezCache-ControlÚ c              3   ó&   •K  — | ]  }|‰v –— Œ
 y ­wr   © )Ú.0Ú	directiveÚcache_controls     €r   ú	<genexpr>z9UpdateCacheMiddleware.process_response.<locals>.<genexpr>i   s   øè ø€ ò !
àð ˜Ô&ñ!
ùs   ƒ)Úprivatezno-cachezno-storeÚ*r   ÚAuthorizationÚpublic)r8   r-   ©r$   Úrenderc                 ó>   •— ‰j                   j                  ‰| ‰«      S r   )r$   Úset)ÚrÚ	cache_keyr   Útimeouts    €€€r   ú<lambda>z8UpdateCacheMiddleware.process_response.<locals>.<lambda>�   s   ø€ ˜dŸj™jŸn™n¨Y¸¸7ÓC€ r    )r+   Ú	streamingÚstatus_codeÚcookiesr   ÚgetÚlowerÚanyr   r   r   r
   Úheadersr   r	   r   r$   r(   Úcallabler;   Úadd_post_render_callbackr=   )r   r)   r*   r4   r?   r@   s   `  @@@r   Úprocess_responsez&UpdateCacheMiddleware.process_responseX   sy  û€ à×(Ñ(¨°(Ô;àˆOà×Ò ×!5Ñ!5¸ZÑ!GØˆOð ×Ò¤°¸(Ô CØˆOð !Ÿ™ _°bÓ9×?Ñ?ÓAˆÙœSó !
ðô!
ô 
ð ˆOô ˜8 SÔ)ØˆOð ×#Ñ#ˆØˆ?ô " (Ó+ˆGØˆØ×,Ñ,‘Ø˜A’à�Ü˜x¨Ô1ð
 �?‰?×Ñ˜Ô/°HÀMÑ4QÜ˜xÐ);Ô<Ù�x×+Ñ+¨sÒ2Ü'Ø˜ 7¨D¯O©OÀ4Ç:Á:ôˆIô �x Ô*¬x¸¿¹Ô/HØ×1Ñ1ÝCôð
 ˆð —
‘
—‘˜y¨(°GÔ<Øˆr    )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr$   r+   rK   Ú__classcell__©r   s   @r   r   r   @   s,   ø„ ñô;ð ñ(ó ð(òWö<r    r   c                   ó8   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zˆ xZS )ÚFetchFromCacheMiddlewarea!  
    Request-phase cache middleware that fetches a page from the cache.

    Must be used as part of the two-part update/fetch cache middleware.
    FetchFromCacheMiddleware must be the last piece of middleware in MIDDLEWARE
    so that it'll get called last during the request phase.
    c                 óx   •— t         ‰| �  |«       t        j                  | _        t        j
                  | _        y r   )r   r   r   r   r   r   r   r   s     €r   r   z!FetchFromCacheMiddleware.__init__    s+   ø€ Ü‰Ñ˜Ô&Ü"×>Ñ>ˆŒÜ#×:Ñ:ˆÕr    c                 ó(   — t         | j                     S r   r"   r#   s    r   r$   zFetchFromCacheMiddleware.cache¥   r%   r    c                 ó&  — |j                   dvrd|_        yt        || j                  d| j                  ¬«      }|€d|_        y| j                  j                  |«      }|€M|j                   dk(  r>t        || j                  d| j                  ¬«      }| j                  j                  |«      }|€d|_        yt        |«      x}�Et        |d   «      x}	 �4t        t        j                  «       «      }||z
  }t        d	||z
  «      |d
<   d|_        |S )zn
        Check whether the page is already cached and return the cached
        version if available.
        )ÚGETÚHEADFNrX   r:   TrY   ÚExpiresr   ÚAge)Úmethodr'   r   r   r$   rE   r   r   ÚintÚtimeÚmax)r   r)   r?   r*   Úmax_age_secondsÚexpires_timestampÚnow_timestampÚremaining_secondss           r   Úprocess_requestz(FetchFromCacheMiddleware.process_request©   s  € ð
 �>‰> Ñ0Ø*/ˆGÔ'Øô " '¨4¯?©?¸EÈÏÉÔTˆ	ØÐØ*.ˆGÔ'ØØ—:‘:—>‘> )Ó,ˆð Ð §¡°&Ò 8Ü%Ø˜Ÿ™¨&¸¿
¹
ôˆIð —z‘z—~‘~ iÓ0ˆHàÐØ*.ˆGÔ'Øô  +¨8Ó4Ð4ˆOÐAÜ!5°h¸yÑ6IÓ!JÐJÐØðGô  ¤§	¡	£Ó,ˆMØ 1°MÑ AÐä! ! _Ð7HÑ%HÓIˆH�U‰Oð ',ˆÔ#Øˆr    )	rL   rM   rN   rO   r   rP   r$   rd   rQ   rR   s   @r   rT   rT   —   s&   ø„ ñô;ð
 ñ(ó ð(ö&r    rT   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚCacheMiddlewarezÌ
    Cache middleware that provides basic behavior for many simple sites.

    Also used as the hook point for the cache decorator, which is generated
    using the decorator-from-middleware utility.
    c                 óÌ   •— t         ‰| �  |«       	 |d   }|€d}|| _        	 |d   }|€t        }|| _        |�|| _        || _        y # t        $ r Y Œ1w xY w# t        $ r Y Œ+w xY w)Nr   r/   r   )r   r   r   ÚKeyErrorr   r   r   r   )r   r   r   r   Úkwargsr   r   r   s          €r   r   zCacheMiddleware.__init__Ú   s’   ø€ Ü‰Ñ˜Ô&ð	Ø Ñ-ˆJØÐ!Ø�
Ø(ˆDŒOð	Ø  Ñ/ˆKØÐ"Ü1�Ø*ˆDÔð Ð$Ø!.ˆDÔØ(ˆÕøô ò 	Ùð	ûô ò 	Ùð	ús"   ’A £A Á	AÁAÁ	A#Á"A#)NN)rL   rM   rN   rO   r   rQ   rR   s   @r   rf   rf   Ò   s   ø„ ñ÷)ñ )r    rf   )rO   r^   Údjango.confr   Údjango.core.cacher   r   Údjango.utils.cacher   r   r   r	   r
   r   Údjango.utils.deprecationr   Údjango.utils.httpr   r   rT   rf   r1   r    r   ú<module>ro      sT   ðñ-ó^ å  ß 9÷÷ õ 5Ý 2ôT˜Oô Tôn8˜ô 8ôv )Ð+Ð-Eõ  )r    