U ʗRe @@sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z ddl m Z eeZedZd Zd d ZGd d d eZdS)z7 The httplib2 algorithms ported for use with requests. N) parsedate_tz)CaseInsensitiveDict) DictCacheSeparateBodyBaseCache) 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)urirr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/cachecontrol/controller.py parse_urisrc@sfeZdZdZdddZeddZedd Zd d Zd d Z ddZ dddZ dddZ ddZ dS)CacheControllerz4An interface to see if request should cached or not.NTcCs4|dkrtn||_||_|p"t|_|p,d|_dS)N)i,rr )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_urlCszCacheController.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-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_controlGsV     z#CacheController.parse_cache_controlcCsX||j}td|||j}d|kr:tddSd|kr\|ddkr\tddS|j|}|dkr~td dSt|jt r|j |}nd}|j |||}|st d dSt|jtkrd }t||St|j}|rd |kr$d |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| | | kr4tdtd| | |Sd |krTtd|j|dS)ze Return a cached response if it exists in the cache, otherwise return False. zLooking up "%s" in the cacher1z-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: %ir0z'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>rKrBrr9 isinstancerget_bodyrloadswarningr8statusPERMANENT_REDIRECT_STATUSESrdeletetimecalendartimegmrmax)rrequestr.cc cache_data body_filerespmsgrBnowrL current_ageresp_ccfreshness_lifetimerN expire_time min_freshrrrcached_request}s                                zCacheController.cached_requestcCs`||j}|j||j|}i}|r\t|j}d|krH|d|d<d|kr\|d|d<|S)NrMETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r.rOrrRrr9rrB)rr[r.r_ new_headersrBrrrconditional_headerss    z#CacheController.conditional_headerscCs\t|jtr:|jj||j||d|d|j||n|jj||j||||ddS)z. Store the data in the cache. )rNN)rPrrsetrdumpsset_body)rr.r[responsebody expires_timerrr _cache_sets zCacheController._cache_setcCs|p|j}|j|kr(td|j|dSt|j}d|krNtt|d}nd}|dk rd|kr|d rt |dt |krdS| |j}| |} | |j} td| d} d| krd } td d|krd } td | r|j| rtd |j| | rdSd |ddkr8tddS|jrd|krd} |dr~t|d} | dk r~t| |} t| d} td| td|| |||| nt |jtkrtd|| ||dnd|krtt|d}d| kr<| ddkr 0z5Caching b/c of expires header. expires in {0} seconds)rrTr=r>rrBrXrYrisdigitr8lenrKr.rOrr9rVrrZformatrrrU)rr[rorprrresponse_headersrLcc_reqr\r.no_storerqrNrrrcache_responses                         zCacheController.cache_responsecsl||j}|j||j|}|s*|Sdg|jtfdd|j Dd|_ | ||||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. rsc3s&|]\}}|kr||fVqdSr-)r").0kvexcluded_headersrr s z9CacheController.update_cached_response..r) r.rOrrRrr9rBupdatedictitemsrTrr)rr[ror.cached_responserrrupdate_cached_responses    z&CacheController.update_cached_response)NTNN)NN)NN)rA __module__ __qualname____doc__r classmethodr,r.rKrgrjrrr|rrrrrr$s    6u  {r)rloggingrerXrW email.utilsrZpip._vendor.requests.structuresrrrr serializer getLoggerrAr=compilerrUrobjectrrrrrs