o 7]h:@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|pt}||SN)rutcnow)deltadater E/usr/lib/python3/dist-packages/pip/_vendor/cachecontrol/heuristics.py expire_afters r cCstt|Sr)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 rr r r update_headers%szBaseHeuristic.update_headerscCs@||}|r|j|||}|dur|jd|i|S)NWarning)rheadersupdater)rrupdated_headerswarning_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|jvr't|jd}ttddt|ddd}t||d<d|d<|S) Nexpiresr )days)r public cache-control)rrr rrr)rrrr r#r r r r@s  zOneDayCache.update_headersN)rr r!__doc__rr r r r r":s r"c@s(eZdZdZddZddZddZdS) ExpiresAfterz; Cache **all** requests for a defined time period. cKstdi||_dS)Nr )rr )rkwr r r __init__PszExpiresAfter.__init__cCst|j}t|ddS)Nr')r#r()r r r)rrr#r r r rSs zExpiresAfter.update_headerscCsd}||jS)Nz:110 - Automatically cached for %s. Response might be stale)r )rrtmplr r r rWs zExpiresAfter.warningN)rr r!r)r,rrr r r r r*Ks  r*c@s(eZdZdZhdZddZddZdS) 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 Cs|j}d|vr iSd|vr|ddkriS|j|jvriSd|vs%d|vr'iStt|d}t|d}|dus>|dur@iSt}td||}|t|}tdt |dd}||krbiS||} dt t t | iS) Nr#r(r'r z last-modifiedr iQ) rstatuscacheable_by_default_statusesrrrrtimemaxminstrftimeTIME_FMTgmtime) rresprr last_modifiednow current_ager freshness_lifetimer#r r r rls*  zLastModified.update_headerscCsdSrr )rrCr r r rszLastModified.warningN)rr r!r)r<rrr r r r r.\s   r.r)rr= email.utilsrrrrrrAr robjectrr"r*r.r r r r s "