a  zeE7@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 re/opt/bitninja-python-dojo/embedded/lib/python3.9/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. NTcCs4|durtn||_||_|p"t|_|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) clsrscheme authoritypathqueryfragment request_uri 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"tytd |YqPYn0|r| sd||<|rPz||d ||<WqPty| rtd |YqPtytd||j YqP0qP|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_controlBsV       z#CacheController.parse_cache_controlcCs0||j}td|||j}d|vr:tddSd|vr\|ddkr\tddS|j|}|dur~td dS|j ||}|st d dS|j d krd }t||St |j}|rd |vrd|vrtd|j |tddSt}tt|d } td|| } td| ||} d} d| vr^| d} td| nDd|vrt|d} | durt| | }td|} td| d|vr|d} td| d|vr|d}| |7} td| | | kr tdtd| | |Sd|vr,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,urlr;r<rIr@rr7rloadswarningstatusrdeletetimecalendartimegmrmax)rrequestr,cc cache_datarespmsgr@nowrJ current_ageresp_ccfreshness_lifetimerL expire_time min_freshrrrcached_requestxsz                               zCacheController.cached_requestcCs`||j}|j||j|}i}|r\t|j}d|vrH|d|d<d|vr\|d|d<|S)NrKETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r,rMrrNrr7rr@)rrVr,rY new_headersr@rrrconditional_headerss    z#CacheController.conditional_headersc Cs|p|j}|j|vr(td|j|dSt|j}|durfd|vrf|drft|dt|krfdS| |j}| |}| |j } td| d} d|vrd} tdd|vrd} td | r|j | rtd |j | | rdSd | d d vrtddS|jrLd|vrLtd|j | |jj|||dn|jdkr|td|j | |j||nd|vrd|vr|ddkrtd|j | |jj|||dn:d|vr|drtd|j | |jj|||ddS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sNcontent-lengthz&Updating cache with response from "%s"Fr0TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyr3zResponse header has "Vary: *"rKzCaching due to etag)bodyrzCaching permanant redirectrJr-rz'Caching b/c date exists and max-age > 0rLzCaching b/c of expires header)rrPr;r<rr@isdigitr6lenrIr,rMrr7rQrsetrdumps) rrVresponserhrrresponse_headerscc_reqrWr,no_storerrrcache_responsesn                     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. rec3s&|]\}}|vr||fVqdSr+)r ).0kvexcluded_headersrr ks z9CacheController.update_cached_response..r) r,rMrrNrr7r@updatedictitemsrPrkrl)rrVrmr,cached_responserrurupdate_cached_responseRs    z&CacheController.update_cached_response)NTNN)NN) r? __module__ __qualname____doc__r classmethodr*r,rIrardrqr|rrrrrs   6o [r)rloggingrerSrR email.utilsrZpip._vendor.requests.structuresrrr serializer getLoggerr?r;compiler robjectrrrrrs