
    .Ph                        d dl mZ d dlZd dlZd dlmZmZmZ d dlmZm	Z	m
Z
 d dlmZmZmZ erd dlmZ dZdddZddZ G d d          Z G d de          Z G d de          Z G d de          ZdS )    )annotationsN)datetime	timedeltatimezone)
formatdate	parsedateparsedate_tz)TYPE_CHECKINGAnyMapping)HTTPResponsez%a, %d %b %Y %H:%M:%S GMTdeltar   datedatetime | Nonereturnr   c                L    |pt          j        t          j                  }|| z   S N)r   nowr   utc)r   r   s     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/cachecontrol/heuristics.pyexpire_afterr      s"    -8<--D%<    dtstrc                h    t          t          j        |                                                     S r   )r   calendartimegm	timetuple)r   s    r   datetime_to_headerr      s"    hobllnn55666r   c                  &    e Zd Zd
dZddZddZd	S )BaseHeuristicresponser   r   
str | Nonec                    dS )a!  
        Return a valid 1xx warning header value describing the cache
        adjustments.

        The response is provided too allow warnings like 113
        http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
        to explicitly say response is over 24 hours old.
        z110 - "Response is Stale" selfr"   s     r   warningzBaseHeuristic.warning   s
     +*r   dict[str, str]c                    i S )zUpdate the response headers with any new headers.

        NOTE: This SHOULD always include some Warning header to
              signify that the response was cached by the client, not
              by way of the provided headers.
        r%   r&   s     r   update_headerszBaseHeuristic.update_headers'   s	     	r   c                    |                      |          }|rM|j                            |           |                     |          }||j                            d|i           |S )NWarning)r+   headersupdater(   )r'   r"   updated_headerswarning_header_values       r   applyzBaseHeuristic.apply0   so    --h77 	K##O444#'<<#9#9 #/ ''4H(IJJJr   Nr"   r   r   r#   r"   r   r   r)   )r"   r   r   r   )__name__
__module____qualname__r(   r+   r2   r%   r   r   r!   r!      sP        	+ 	+ 	+ 	+   	 	 	 	 	 	r   r!   c                      e Zd ZdZddZdS )	OneDayCachezM
    Cache the response by providing an expires 1 day in the
    future.
    r"   r   r   r)   c                    i }d|j         vrlt          |j         d                   }t          t          d          t	          |d d         dt
          j        i          }t          |          |d<   d|d	<   |S )
Nexpiresr      )days   tzinfo)r   publiccache-control)r.   r   r   r   r   r   r   r   )r'   r"   r.   r   r;   s        r   r+   zOneDayCache.update_headersB   s    H,,,X-f566D"q!!!tBQBx===  G "4G!<!<GI'/GO$r   Nr4   )r5   r6   r7   __doc__r+   r%   r   r   r9   r9   <   s2         
     r   r9   c                  *    e Zd ZdZddZdd
ZddZdS )ExpiresAfterz;
    Cache **all** requests for a defined time period.
    kwr   r   Nonec                (    t          di || _        d S )Nr%   )r   r   )r'   rE   s     r   __init__zExpiresAfter.__init__U   s    ____


r   r"   r   r)   c                N    t          | j                  }t          |          ddS )Nr@   )r;   rA   )r   r   r   )r'   r"   r;   s      r   r+   zExpiresAfter.update_headersX   s'    tz**-g66RRRr   r#   c                    d}|| j         z  S )Nz:110 - Automatically cached for %s. Response might be stale)r   )r'   r"   tmpls      r   r(   zExpiresAfter.warning\   s    Kdj  r   N)rE   r   r   rF   r4   r3   )r5   r6   r7   rB   rH   r+   r(   r%   r   r   rD   rD   P   s^         % % % %S S S S! ! ! ! ! !r   rD   c                  *    e Zd ZdZh dZddZdd	Zd
S )LastModifieda  
    If there is no Expires header already, fall back on Last-Modified
    using the heuristic from
    http://tools.ietf.org/html/rfc7234#section-4.2.2
    to calculate a reasonable value.

    Firefox also does something like this per
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching_FAQ
    http://lxr.mozilla.org/mozilla-release/source/netwerk/protocol/http/nsHttpResponseHead.cpp#397
    Unlike mozilla we limit this to 24-hr.
    >   ,  -                        respr   r   r)   c                B   |j         }d|v ri S d|v r|d         dk    ri S |j        | j        vri S d|vsd|vri S t          |d                   }|J t	          j        |d d                   }t          |d                   }|i S t          j                    }t          d||z
            }|t	          j        |          z
  }t          dt          |dz  d	                    }	|	|k    ri S ||	z   }
dt          j
        t          t          j        |
                    iS )
Nr;   rA   r@   r   zlast-modifiedr>   r   
   iQ )r.   statuscacheable_by_default_statusesr	   r   r   r   timemaxminstrftimeTIME_FMTgmtime)r'   rY   r.   
time_tupler   last_modifiedr   current_ager   freshness_lifetimer;   s              r   r+   zLastModified.update_headers|   sD   %)\Ig%%'/*Bh*N*NI;d@@@I  O7$B$BI!'&/22
%%%z"1"~..!'/":;; Iikk!S4Z((x}555 C
I$>$>??,,I++4=4;w3G3GHHIIr   r#   c                    d S r   r%   )r'   rY   s     r   r(   zLastModified.warning   s    tr   N)rY   r   r   r)   )rY   r   r   r#   )r5   r6   r7   rB   r]   r+   r(   r%   r   r   rM   rM   a   s]        
 
% % %!J J J J@     r   rM   r   )r   r   r   r   r   r   )r   r   r   r   )
__future__r   r   r^   r   r   r   email.utilsr   r   r	   typingr
   r   r   urllib3r   rb   r   r   r!   r9   rD   rM   r%   r   r   <module>rm      s   # " " " " "   2 2 2 2 2 2 2 2 2 2 ; ; ; ; ; ; ; ; ; ; . . . . . . . . . . %$$$$$$&    
7 7 7 7       B    -   (! ! ! ! != ! ! !"< < < < <= < < < < <r   