o 7]h =@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z e eZedZd Zd d ZGd d d eZdS)z7 The httplib2 algorithms ported for use with requests. N) parsedate_tz)CaseInsensitiveDict) DictCache) Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)-4cCs0t|}|d|d|d|d|dfS)zParses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) r)URImatchgroups)urirrE/usr/lib/python3/dist-packages/pip/_vendor/cachecontrol/controller.py parse_uris"rc@s^eZdZdZ dddZeddZedd Zd d Zd d Z ddZ dddZ ddZ dS)CacheControllerz9An interface to see if request should cached or not. NTcCs4|durtn||_||_|pt|_|pd|_dS)N)i,rr)rcache cache_etagsr serializercacheable_status_codes)selfrrr status_codesrrr__init__(s zCacheController.__init__c Csht|\}}}}}|r |std||}|}|sd}|r(d||gp)|}|d||}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %s/?z://)r Exceptionlowerjoin) clsrscheme authoritypathqueryfragment request_uri defrag_urirrr_urlnorm0s zCacheController._urlnormcCs ||SN)r+)r#rrrr cache_urlDs zCacheController.cache_urlc Cstdftdftdfddddddddtdfd }|d|dd}i}|dD]c}|s/q(|d d }|d }z||\}} WntyRtd |Yq(w|rW| s[d||<|rz ||d ||<Wq(tyz| rxtd |Yq(tytd||j Yq(wq(|S)NTF)NF) max-agez max-stale min-freshno-cacheno-storez no-transformzonly-if-cachedzmust-revalidatepublicprivatezproxy-revalidatezs-maxagez cache-controlz Cache-Control,=rrz,Ignoring unknown cache-control directive: %sz-Missing value for cache-control directive: %sz8Invalid value for cache-control directive %s, must be %s) intgetsplitstripKeyErrorloggerdebug IndexError ValueError__name__) rheadersknown_directives cc_headersretval cc_directiveparts directivetyprequiredrrrparse_cache_controlHs^      z#CacheController.parse_cache_controlcCs*||j}td|||j}d|vrtddSd|vr.|ddkr.tddS|j|}|dur?td dS|j ||}|sOt d dSt |j t vr_d }t||St|j}|rjd |vrd |vrytd|j|tddSt}tt|d } td|| } td| ||} d} d| vr| d} td| n d|vrt|d} | durt| | }td|} td| d|vr|d} td| d|vr|d}| |7} td| | | krtdtd| | |Sd |vrtd|j|dS)ze Return a cached response if it exists in the cache, otherwise return False. zLooking up "%s" in the cacher0z-Request header has "no-cache", cache bypassedFr.rz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredzQReturning cached permanent redirect response (ignoring date and etag information)dateetagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %iexpiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %ir/z'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r-urlr<r=rJrArr8rloadswarningr7statusPERMANENT_REDIRECT_STATUSESrdeletetimecalendartimegmrmax)rrequestr-cc cache_datarespmsgrAnowrK current_ageresp_ccfreshness_lifetimerM expire_time min_freshrrrcached_request~sz                          zCacheController.cached_requestcCs`||j}|j||j|}i}|r.t|j}d|vr$|d|d<d|vr.|d|d<|S)NrLETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r-rNrrOrr8rrA)rrXr-r[ new_headersrArrrconditional_headerss    z#CacheController.conditional_headerscCs|p|j}|j|vrtd|j|dSt|j}d|vr'tt|d}nd}|durCd|vrC|d rCt |dt |krCdS| |j}| |} | |j} td| d} d| vrgd } td d|vrrd } td | r|j| rtd |j| | rdSd |ddvrtddS|jrd|vrd} |drt|d} | durt| |} t| d} td| td|jj| |j|||| ddSt |jtvrtd|j| |j||ddSd|vrbtt|d}d| vr)| ddkr)td| d} |jj| |j|||| ddSd|vrd|drft|d} | durFt| |} nd} td| |jj| |jj|||d| ddSdSdSdS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sNrKrcontent-lengthz&Updating cache with response from "%s"Fr1TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyr4zResponse header has "Vary: *"rLrMiuz"etag object cached for {0} secondszCaching due to etag)rMzCaching permanent redirectr.z'Caching b/c date exists and max-age > 0z5Caching b/c of expires header. expires in {0} seconds)body)rrQr<r=rrArUrVrisdigitr7lenrJr-rNrr8rSrrWformatsetrdumpsrR)rrXresponserkrrresponse_headersrKcc_reqrYr-no_store expires_timerMrrrcache_responses                          zCacheController.cache_responsecsv||j}|j||j|}|s|Sdg|jtfdd|j Dd|_ |j ||j |||S)zOn a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response. rgc3s(|]\}}|vr||fVqdSr,)r!).0kvexcluded_headersrr s z9CacheController.update_cached_response..r) r-rNrrOrr8rAupdatedictitemsrQrorp)rrXrqr-cached_responserrzrupdate_cached_responseys    z&CacheController.update_cached_response)NTNN)NN) r@ __module__ __qualname____doc__r classmethodr+r-rJrcrfrvrrrrrr$s   6p  {r)rloggingrerUrT email.utilsrpip._vendor.requests.structuresrrr serializer getLoggerr@r<compiler rRrobjectrrrrrs