3 Re@sddlZddlZddlmZmZmZddlmZmZdZdddZ ddZ Gd d d e Z Gd d d e Z Gd dde ZGddde ZdS)N) formatdate parsedate parsedate_tz)datetime timedeltaz%a, %d %b %Y %H:%M:%S GMTcCs|p tj}||S)N)rutcnow)deltadater /builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/cachecontrol/heuristics.py expire_after s r cCsttj|jS)N)rcalendartimegm timetuple)dtr r r datetime_to_headersrc@s$eZdZddZddZddZdS) BaseHeuristiccCsdS)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. z110 - "Response is Stale"r )selfresponser r r warnings zBaseHeuristic.warningcCsiS)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 )rrr r r update_headers!szBaseHeuristic.update_headerscCs@|j|}|r<|jj||j|}|dk r<|jjd|i|S)NWarning)rheadersupdater)rrZupdated_headersZwarning_header_valuer r r apply*s   zBaseHeuristic.applyN)__name__ __module__ __qualname__rrrr r r r rs  rc@seZdZdZddZdS) OneDayCachezM Cache the response by providing an expires 1 day in the future. cCsRi}d|jkrNt|jd}ttddt|ddd}t||d<d|d<|S) Nexpiresr )days)r publicz cache-control)rrr rrr)rrrr rr r r r<s  zOneDayCache.update_headersN)rrr__doc__rr r r r r6src@s(eZdZdZddZddZddZdS) ExpiresAfterz; Cache **all** requests for a defined time period. cKstf||_dS)N)rr)rkwr r r __init__LszExpiresAfter.__init__cCst|j}t|ddS)Nr#)rz cache-control)r rr)rrrr r r rOs zExpiresAfter.update_headerscCsd}||jS)Nz:110 - Automatically cached for %s. Response might be stale)r)rrtmplr r r rSszExpiresAfter.warningN)rrrr$r'rrr r r r r%Gsr%c @s:eZdZdZdddddddd d d d h Zd dZddZdS) 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. i,i-iiiiic Cs|j}d|kriSd|kr*|ddkr*iS|j|jkr:iSd|ksJd|krNiStjt|d}t|d}|dks||dkriStj}td||}|tj|}tdt |dd }||kriS||} dtj t tj | iS) Nrz cache-controlr#r z last-modifiedr iiQ) rstatuscacheable_by_default_statusesr rrrtimemaxminstrftimeTIME_FMTgmtime) rresprr Z last_modifiednow current_agerfreshness_lifetimerr r r rhs*  zLastModified.update_headerscCsdS)Nr )rr8r r r rszLastModified.warningN)rrrr$r1rrr r r r r)Xs r))N)r r2 email.utilsrrrrrr6r robjectrrr%r)r r r r s "