
    )h                        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y)    )annotationsN)datetime	timedeltatimezone)
formatdate	parsedateparsedate_tz)TYPE_CHECKINGAnyMapping)HTTPResponsez%a, %d %b %Y %H:%M:%S GMTc                Z    |xs# t        j                  t        j                        }|| z   S N)r   nowr   utc)deltadates     V/var/www/html/venv/lib/python3.12/site-packages/pip/_vendor/cachecontrol/heuristics.pyexpire_afterr      s#    -8<<-D%<    c                Z    t        t        j                  | j                                     S r   )r   calendartimegm	timetuple)dts    r   datetime_to_headerr      s    hooblln566r   c                  $    e Zd ZddZddZddZy)BaseHeuristicc                     y)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" selfresponses     r   warningzBaseHeuristic.warning   s     +r   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                    | j                  |      }|rK|j                  j                  |       | j                  |      }||j                  j                  d|i       |S )NWarning)r&   headersupdater$   )r"   r#   updated_headerswarning_header_values       r   applyzBaseHeuristic.apply0   s]    --h7##O4#'<<#9 #/  ''4H(IJr   Nr#   r   return
str | Noner#   r   r/   dict[str, str])r#   r   r/   r   )__name__
__module____qualname__r$   r&   r-   r    r   r   r   r      s    	+	r   r   c                      e Zd ZdZddZy)OneDayCachezM
    Cache the response by providing an expires 1 day in the
    future.
    c                    i }d|j                   vr\t        |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   r9   s        r   r&   zOneDayCache.update_headersB   ss    H,,,X--f56D"q!tBQx==G "4G!<GI'/GO$r   Nr1   )r3   r4   r5   __doc__r&   r    r   r   r7   r7   <   s    
r   r7   c                  (    e Zd ZdZddZddZddZy)	ExpiresAfterz;
    Cache **all** requests for a defined time period.
    c                $    t        di || _        y )Nr    )r   r   )r"   kws     r   __init__zExpiresAfter.__init__U   s    __
r   c                H    t        | j                        }t        |      ddS )Nr>   )r9   r?   )r   r   r   )r"   r#   r9   s      r   r&   zExpiresAfter.update_headersX   s     tzz*-g6RRr   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djj  r   N)rD   r   r/   Noner1   r.   )r3   r4   r5   r@   rE   r&   r$   r    r   r   rB   rB   P   s    %S!r   rB   c                  (    e Zd ZdZh dZddZddZy)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.
    >   ,  -                        c                    |j                   }d|v ri S d|v r
|d   dk7  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 )
Nr9   r?   r>   r   zlast-modifiedr<   r   
   iQ )r)   statuscacheable_by_default_statusesr	   r   r   r   timemaxminstrftimeTIME_FMTgmtime)r"   respr)   
time_tupler   last_modifiedr   current_ager   freshness_lifetimer9   s              r   r&   zLastModified.update_headers|   s!   %)\\Ig%'/*Bh*NI;;d@@@I O7$BI!'&/2
%%%z"1~.!'/":; Iiik!S4Z(x}55 C
I$>?,I++4==4;;w3GHIIr   c                     y r   r    )r"   ra   s     r   r$   zLastModified.warning   s    r   N)ra   r   r/   r2   )ra   r   r/   r0   )r3   r4   r5   r@   rZ   r&   r$   r    r   r   rK   rK   a   s    
%!J@r   rK   r   )r   r   r   zdatetime | Noner/   r   )r   r   r/   str)
__future__r   r   r[   r   r   r   email.utilsr   r   r	   typingr
   r   r   pip._vendor.urllib3r   r_   r   r   r   r7   rB   rK   r    r   r   <module>rl      sf    #   2 2 ; ; . .0&
7 B- (!= !"<= <r   