a [›ýfE7ã@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úG/usr/lib/python3.9/site-packages/pip/_vendor/cachecontrol/controller.pyÚ parse_urisrc@s\eZdZdZddd„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||_||_|p"tƒ|_|p,d|_dS)N)éÈéËi,é-)rÚcacheÚ cache_etagsrÚ serializerÚcacheable_status_codes)ÚselfrrrÚ status_codesrrrÚ__init__"s zCacheController.__init__c Csht|ƒ\}}}}}|r|s&td|ƒ‚| ¡}| ¡}|s>d}|rPd ||g¡pR|}|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ÚschemeZ authorityÚpathÚqueryÚfragmentZ request_uriZ defrag_urirrrÚ_urlnorm*s zCacheController._urlnormcCs | |¡S©N)r')r"rrrrÚ cache_url>szCacheController.cache_urlc Cs"tdftdftdfddddddddtdfdœ }| d| dd¡¡}i}| d¡D]Ì}| ¡s^qP| d d ¡}|d  ¡}z||\}} Wn"ty¨t d |¡YqPYn0|r²| sºd||<|rPz||d  ¡ƒ||<WqPtyø| rôt d |¡YqPtyt d||j ¡YqP0qP|S)NTF)NF) úmax-agez max-staleú min-freshúno-cacheúno-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) ÚintÚgetÚsplitÚstripÚKeyErrorÚloggerÚdebugÚ IndexErrorÚ ValueErrorÚ__name__) rÚheadersZknown_directivesZ cc_headersZretvalZ cc_directiveÚpartsZ directiveÚtypÚrequiredrrrÚparse_cache_controlBsVó      þý z#CacheController.parse_cache_controlcCs0| |j¡}t d|¡| |j¡}d|vr:t d¡dSd|vr\|ddkr\t d¡dS|j |¡}|dur~t d ¡dS|j  ||¡}|sžt  d ¡dS|j d krºd }t |¡|St |jƒ}|rÐd |vrüd|vrît d¡|j  |¡t d¡dSt ¡}t t|d ƒ¡} td|| ƒ} t d| ¡| |¡} d} d| vr^| d} t d| ¡nDd|vr¢t|dƒ} | dur¢t | ¡| }td|ƒ} t d| ¡d|vrÀ|d} t d| ¡d|vræ|d}| |7} t d| ¡| | kr t d¡t d| | ¡|Sd|vr,t 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)Úurlr6r7r?r;rr2rÚloadsZwarningÚstatusrÚdeleteÚtimeÚcalendarZtimegmrÚmax)rÚrequestr)ÚccZ cache_dataÚrespÚmsgr;Znowr@Z current_ageZresp_ccZfreshness_lifetimerBZ expire_timeZ min_freshrrrÚcached_requestxsz         ÿ               ÿ       zCacheController.cached_requestcCs`| |j¡}|j ||j |¡¡}i}|r\t|jƒ}d|vrH|d|d<d|vr\|d|d<|S)NrAZETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r)rCrrDrr2rr;)rrJr)rLZ new_headersr;rrrÚconditional_headersçs    z#CacheController.conditional_headersc Cs|p|j}|j|vr(t d|j|¡dSt|jƒ}|durfd|vrf|d ¡rft|dƒt|ƒkrfdS|  |j¡}|  |¡}|  |j ¡} t d| ¡d} d|vr®d} t d¡d|vrÄd} t d ¡| rê|j   | ¡rêt d ¡|j  | ¡| ròdSd |  d d ¡vrt d¡dS|jrLd|vrLt d¡|j  | |jj|||d¡n´|jdkr|t d¡|j  | |j ||¡¡n„d|vrd|vrÆ|ddkrÆt d¡|j  | |jj|||d¡n:d|vr|drt d¡|j  | |jj|||d¡dS)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"Fr-TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"Ú*Zvaryr.zResponse header has "Vary: *"rAzCaching due to etag)ÚbodyrzCaching permanant redirectr@r*rz'Caching b/c date exists and max-age > 0rBzCaching b/c of expires header)rrEr6r7rr;Úisdigitr1Úlenr?r)rCrr2rFrÚsetrÚdumps) rrJÚresponserRrrZresponse_headersZcc_reqrKr)Zno_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. rPc3s&|]\}}| ¡ˆvr||fVqdSr()r )Ú.0ÚkÚv©Zexcluded_headersrrÚ ks þz9CacheController.update_cached_response..r) r)rCrrDrr2r;ÚupdateÚdictÚitemsrErUrV)rrJrWr)Zcached_responserr\rÚupdate_cached_responseRs   þÿ z&CacheController.update_cached_response)NTNN)NN) r:Ú __module__Ú __qualname__Ú__doc__rÚ classmethodr'r)r?rNrOrXrarrrrrsÿ   6o [r)rdZloggingÚrerHrGZ email.utilsrZpip._vendor.requests.structuresrrrZ serializerZ getLoggerr:r6Úcompiler rÚobjectrrrrrÚs