U .e5@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z e eZedZd d ZGd d d eZdS) z7 The httplib2 algorithms ported for use with requests. N) parsedate_tz)CaseInsensitiveDict) DictCache) Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0t|}|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)urir rG/usr/lib/python3.8/site-packages/pip/_vendor/cachecontrol/controller.py parse_urisrc@s\eZdZdZdddZeddZedd Zd d Zd d Z ddZ dddZ ddZ dS)CacheControllerz9An interface to see if request should cached or not. NTcCs,|pt|_||_|pt|_|p$d|_dS)N)i,-)rcache cache_etagsr serializercacheable_status_codes)selfrrr status_codesrrr__init__"s  zCacheController.__init__c Csht|\}}}}}|r|s&td||}|}|s>d}|rPd||gpR|}|d||}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %s/?z://)r Exceptionlowerjoin) clsrZschemeZ authoritypathZqueryZfragmentZ request_uriZ defrag_urirrr_urlnorm*s zCacheController._urlnormcCs ||SN)r$)r"rrrr cache_url>szCacheController.cache_urlc Cs(tdftdftdfddddddddtdfd }|d|dd}i}|dD]}|s^qP|d d }|d }z||\}} Wn$tk rtd |YqPYnX|r| sd||<|rPz||d ||<WqPtk r| rtd |YqPtk r td||j YqPXqP|S)NTF)NF) max-agez max-stale min-freshno-cacheno-storez no-transformzonly-if-cachedzmust-revalidateZpublicZprivatezproxy-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__) rheadersZknown_directivesZ cc_headersZretvalZ cc_directivepartsZ directivetypZrequiredrrrparse_cache_controlBsV     z#CacheController.parse_cache_controlcCs0||j}td|||j}d|kr:tddSd|kr\|ddkr\tddS|j|}|dkr~td dS|j ||}|st d dS|j d krd }t||St |j}|rd |krd|krtd|j |tddSt}tt|d } td|| } td| ||} d} d| kr^| d} td| nDd|krt|d} | dk rt| | }td|} td| d|kr|d} td| d|kr|d}| |7} td| | | kr tdtd| | |Sd|kr,td|j |dS)ze Return a cached response if it exists in the cache, otherwise return False. zLooking up "%s" in the cacher)z-Request header has "no-cache", cache bypassedFr'rz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredrzVReturning cached "301 Moved Permanently" 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&urlr3r4r;r8rr/rloadsZwarningstatusrdeletetimecalendarZtimegmrmax)rrequestr&ccZ cache_datarespmsgr8Znowr<Z current_ageZresp_ccZfreshness_lifetimer>Z expire_timeZ min_freshrrrcached_requestxs|                               zCacheController.cached_requestcCs`||j}|j||j|}i}|r\t|j}d|krH|d|d<d|kr\|d|d<|S)Nr=ZETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r&r?rr@rr/rr8)rrFr&rHZ new_headersr8rrrconditional_headerss    z#CacheController.conditional_headersc Cs|p|j}|j|kr(td|j|dSt|j}|dk rfd|krf|drft|dt|krfdS| |j}| |}| |j } td| d} d|krd} tdd|krd} td | r|j | rtd |j | | rdS|jr,d |kr,td |j | |jj|||d n|jdkr\td|j | |j||nd|krd|kr|ddkrtd|j | |jj|||d n:d|kr|drtd|j | |jj|||d dS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sNcontent-lengthz&Updating cache with response from "%s"Fr*TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"r=zCaching due to etag)bodyrzCaching permanant redirectr<r'rz'Caching b/c date exists and max-age > 0r>zCaching b/c of expires header)rrAr3r4rr8isdigitr.lenr;r&r?rr/rBrsetrdumps) rrFresponserMrrZresponse_headersZcc_reqrGr&Zno_storerrrcache_responsesr                    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. rLc3s&|]\}}|kr||fVqdSr%)r ).0kvZexcluded_headersrr bs z9CacheController.update_cached_response..r) r&r?rr@rr/r8updatedictitemsrArPrQ)rrFrRr&Zcached_responserrWrupdate_cached_responseIs    z&CacheController.update_cached_response)NTNN)NN) r7 __module__ __qualname____doc__r classmethodr$r&r;rJrKrSr\rrrrrs   6o Rr)r_ZloggingrerDrCZ email.utilsrZpip._vendor.requests.structuresrrrZ serializerZ getLoggerr7r3compiler robjectrrrrrs