o aiE7ã@s„dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z e  e¡Ze d¡Zd d „ZGd d „d eƒZdS) z7 The httplib2 algorithms ported for use with requests. éN)Ú parsedate_tz)ÚCaseInsensitiveDicté)Ú DictCache)Ú Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0t |¡ ¡}|d|d|d|d|dfS)z‡Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) réééé)ÚURIÚmatchÚgroups)Úurir ©rú•/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/cachecontrol/controller.pyÚ parse_uris"rc@s^eZdZdZ ddd„Zedd„ƒZedd „ƒZd d „Zd d „Z dd„Z ddd„Z dd„Z dS)ÚCacheControllerz9An interface to see if request should cached or not. NTcCs4|durtƒn||_||_|ptƒ|_|pd|_dS)N)éÈéËi,é-)rÚcacheÚ cache_etagsrÚ serializerÚcacheable_status_codes)ÚselfrrrÚ status_codesrrrÚ__init__"s zCacheController.__init__c Csht|ƒ\}}}}}|r |std|ƒ‚| ¡}| ¡}|sd}|r(d ||g¡p)|}|d||}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %sú/ú?z://)rÚ ExceptionÚlowerÚjoin) ÚclsrÚschemeÚ authorityÚpathÚqueryÚfragmentÚ request_uriÚ defrag_urirrrÚ_urlnorm*s zCacheController._urlnormcCs | |¡S©N)r*)r"rrrrÚ cache_url>s zCacheController.cache_urlc Cstdftdftdfddddddddtdfdœ }| d| dd¡¡}i}| d¡D]c}| ¡s/q(| d d ¡}|d  ¡}z||\}} WntyRt d |¡Yq(w|rW| s[d||<|r‹z ||d  ¡ƒ||<Wq(tyz| rxt d |¡Yq(tyŠt d||j ¡Yq(wq(|S)NTF)NF) úmax-agez max-staleú min-freshúno-cacheúno-storez no-transformzonly-if-cachedzmust-revalidateÚpublicÚprivatezproxy-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) ÚintÚgetÚsplitÚstripÚKeyErrorÚloggerÚdebugÚ IndexErrorÚ ValueErrorÚ__name__) rÚheadersÚknown_directivesÚ cc_headersÚretvalÚ cc_directiveÚpartsÚ directiveÚtypÚrequiredrrrÚparse_cache_controlBs^ó    þ þ€ ýÿ÷z#CacheController.parse_cache_controlcCs&| |j¡}t d|¡| |j¡}d|vrt d¡dSd|vr.|ddkr.t d¡dS|j |¡}|dur?t d ¡dS|j  ||¡}|sOt  d ¡dS|j d kr]d }t |¡|St |jƒ}|rhd |vr~d|vrwt d¡|j  |¡t d¡dSt ¡}t t|d ƒ¡} td|| ƒ} t d| ¡| |¡} d} d| vr®| d} t d| ¡n d|vrÎt|dƒ} | durÎt | ¡| }td|ƒ} t d| ¡d|vrÜ|d} t d| ¡d|vrî|d}| |7} t d| ¡| | krt d¡t d| | ¡|Sd|vrt d¡|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)ÚdateÚetagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %iÚexpiresz#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@rr7rÚloadsÚwarningÚstatusrÚdeleteÚtimeÚcalendarÚtimegmrÚmax)rÚrequestr,ÚccÚ cache_dataÚrespÚmsgr@ÚnowrJÚ current_ageÚresp_ccÚfreshness_lifetimerLÚ expire_timeÚ min_freshrrrÚcached_requestxsz         ÿ           ÿ      zCacheController.cached_requestcCs`| |j¡}|j ||j |¡¡}i}|r.t|jƒ}d|vr$|d|d<d|vr.|d|d<|S)NrKÚETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r,rMrrNrr7rr@)rrVr,rYÚ new_headersr@rrrÚconditional_headersçs    z#CacheController.conditional_headersc Cs|p|j}|j|vrt d|j|¡dSt|jƒ}|dur3d|vr3|d ¡r3t|dƒt|ƒkr3dS|  |j¡}|  |¡}|  |j ¡} t d| ¡d} d|vrWd} t d¡d|vrbd} t d ¡| ru|j   | ¡rut d ¡|j  | ¡| rydSd |  d d ¡vrˆt d¡dS|jr¤d|vr¤t d¡|j  | |jj|||d¡dS|jdkr¼t d¡|j  | |j ||¡¡dSd|vrýd|vrß|ddkrßt d¡|j  | |jj|||d¡dSd|vrÿ|drt d¡|j  | |jj|||d¡dSdSdSdS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sNúcontent-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@Úisdigitr6ÚlenrIr,rMrr7rQrÚsetrÚdumps) rrVÚresponserhrrÚresponse_headersÚcc_reqrWr,Úno_storerrrÚcache_response÷sn  ÿ  ÿ          ÿ   ÿ  ÿó zCacheController.cache_responsecsv| |j¡}|j ||j |¡¡}|s|Sdg‰|j t‡fdd„|j  ¡Dƒƒ¡d|_ |j  ||j  ||¡¡|S)zéOn 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 )Ú.0ÚkÚv©Úexcluded_headersrrÚ ks€ þýz9CacheController.update_cached_response..r) r,rMrrNrr7r@ÚupdateÚdictÚitemsrPrkrl)rrVrmr,Úcached_responserrurÚupdate_cached_responseRs   þÿ z&CacheController.update_cached_response)NTNN)NN) r?Ú __module__Ú __qualname__Ú__doc__rÚ classmethodr*r,rIrardrqr|rrrrrs ÿ  6o  [r)rÚloggingÚrerSrRÚ email.utilsrZpip._vendor.requests.structuresrrrÚ serializerÚ getLoggerr?r;Úcompiler rÚobjectrrrrrÚs