3 Bu_E7@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej eZejdZd d ZGd d d eZdS) z7 The httplib2 algorithms ported for use with requests. N) parsedate_tz)CaseInsensitiveDict) DictCache) Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0tj|j}|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 r/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.x86_64/opt/alt/python36/lib/python3.6/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|dkrtn||_||_|p"t|_|p,d|_dS)N,-)rrrr)rcache cache_etagsr serializercacheable_status_codes)selfrrr status_codesrrr__init__"s zCacheController.__init__c Cslt|\}}}}}| s| r*td||j}|j}|sBd}|rTdj||gpV|}|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 |j|S)N)r+)r#rrrr cache_url>szCacheController.cache_urlc Cs2tdftdftdfddddddddtdfd }|jd|jdd}i}x|jdD]}|js`qR|jdd }|d j}y||\}} Wn"tk rtjd |wRYnX| s| rd||<|rRy||d j||<WqRtk r| rtjd |YqRtk r(tjd ||j YqRXqRW|S)NTF) zmax-agez max-stalez min-freshzno-cachezno-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)NF)NF)NF)NF)NF)NF)NF)NF) intgetsplitstripKeyErrorloggerdebug IndexError ValueError__name__) rheadersknown_directives cc_headersretval cc_directiveparts directivetyprequiredrrrparse_cache_controlBsP      z#CacheController.parse_cache_controlcCs4|j|j}tjd||j|j}d|kr:tjddSd|kr\|ddkr\tjddS|jj|}|dkr~tjd dS|jj ||}|stj d dS|j d krd }tj||St |j}| sd |krd|krtjd|jj |tjddStj}tjt|d } td|| } tjd| |j|} d} d| krb| d} tjd| nDd|krt|d} | dk rtj| | }td|} tjd| d|kr|d} tjd| d|kr|d}| |7} tjd| | | krtjdtjd| | |Sd|kr0tjd|jj |dS)ze Return a cached response if it exists in the cache, otherwise return False. zLooking up "%s" in the cachezno-cachez-Request header has "no-cache", cache bypassedFzmax-agerz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredi-zVReturning 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: %iz min-freshz'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r,urlr7r8rEr<rr3rloadswarningstatusrdeletetimecalendartimegmrmax)rrequestr,cc cache_datarespmsgr<nowrF current_ageresp_ccfreshness_lifetimerH expire_time min_freshrrrcached_requestxsv                              zCacheController.cached_requestcCs`|j|j}|jj||jj|}i}|r\t|j}d|krH|d|d<d|kr\|d|d<|S)NrGETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r,rIrrJrr3rr<)rrRr,rU new_headersr<rrrconditional_headerss    z#CacheController.conditional_headersc Cs|p|j}|j|kr(tjd|j|dSt|j}|dk rfd|krf|djrft|dt|krfdS|j |j}|j |}|j |j } tjd| d} d|krd} tjdd|krd} tjd | r|j j | rtjd |j j| | rdSd |j d d krtjddS|jrLd|krLtjd|j j| |jj|||dn|jdkr|tjd|j j| |jj||nd|krd|kr|ddkrtjd|j j| |jj|||dn:d|kr|drtjd|j j| |jj|||ddS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sNzcontent-lengthz&Updating cache with response from "%s"Fzno-storeTzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyr/zResponse header has "Vary: *"rGzCaching due to etag)bodyi-zCaching permanant redirectrFzmax-agerz'Caching b/c date exists and max-age > 0rHzCaching b/c of expires header)rrLr7r8rr<isdigitr2lenrEr,rIrr3rMrsetrdumps) rrRresponsercrrresponse_headerscc_reqrSr,no_storerrrcache_responses^                      zCacheController.cache_responsecsv|j|j}|jj||jj|}|s*|Sdg|jjtfdd|jj Dd|_ |jj ||jj |||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. zcontent-lengthc3s&|]\}}|jkr||fVqdS)N)r!).0kv)excluded_headersrr lsz9CacheController.update_cached_response..r) r,rIrrJrr3r<updatedictitemsrLrfrg)rrRrhr,cached_responser)rprupdate_cached_responseRs   z&CacheController.update_cached_response)NTNN)NN) r; __module__ __qualname____doc__r classmethodr+r,rEr]r`rlrvrrrrrs   6o [r)ryloggingrerOrN email.utilsrZpip._vendor.requests.structuresrrr serializer getLoggerr;r7compiler robjectrrrrrs