3 ”ReE7ã@s„dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej eƒZejdƒZd d „ZGd d „d eƒZdS) z7 The httplib2 algorithms ported for use with requests. éN)Ú parsedate_tz)ÚCaseInsensitiveDicté)Ú DictCache)Ú Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0tj|ƒjƒ}|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-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/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|dkrtƒn||_||_|p"tƒ|_|p,d|_dS)NéÈéËé,é-)rrrr)rÚcacheÚ cache_etagsrÚ serializerÚcacheable_status_codes)ÚselfrrrÚ status_codesrrrÚ__init__"s zCacheController.__init__c Cslt|ƒ\}}}}}| s| r*td|ƒ‚|jƒ}|jƒ}|sBd}|rTdj||gƒpV|}|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 |j|ƒS)N)r+)r#rrrrÚ cache_url>szCacheController.cache_urlc Cs2tdftdftdfddddddddtdfdœ }|jd|jddƒƒ}i}xæ|jdƒD]Ø}|jƒs`qR|jdd ƒ}|d jƒ}y||\}} Wn"tk rªtjd |ƒwRYnX| s¸| rÀd||<|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-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)NF)NF)NF)NF)NF)NF)NF)NF) Ú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_controlBsP      z#CacheController.parse_cache_controlcCs4|j|jƒ}tjd|ƒ|j|jƒ}d|kr:tjdƒdSd|kr\|ddkr\tjdƒdS|jj|ƒ}|dkr~tjd ƒdS|jj ||ƒ}|sžtj d ƒdS|j d krºd }tj|ƒ|St |jƒ}| sÔd |k�rd|kròtjdƒ|jj |ƒtjdƒdStjƒ}tjt|d ƒƒ} td|| ƒ} tjd| ƒ|j|ƒ} d} d| k�rb| d} tjd| ƒnDd|k�r¦t|dƒ} | dk �r¦tj| ƒ| }td|ƒ} tjd| ƒd|k�rÄ|d} tjd| ƒd|k�rê|d}| |7} tjd| ƒ| | k�rtjdƒtjd| | ƒ|Sd|k�r0tjdƒ|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)Ú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: %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<rr3rÚloadsÚwarningÚstatusrÚdeleteÚtimeÚcalendarÚtimegmrÚmax)rÚrequestr,ÚccÚ cache_dataÚrespÚmsgr<ÚnowrFÚ current_ageÚresp_ccÚfreshness_lifetimerHÚ expire_timeÚ min_freshrrrÚcached_requestxsv                              zCacheController.cached_requestcCs`|j|jƒ}|jj||jj|ƒƒ}i}|r\t|jƒ}d|krH|d|d<d|kr\|d|d<|S)NrGÚETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r,rIrrJrr3rr<)rrRr,rUÚ new_headersr<rrrÚconditional_headersçs    z#CacheController.conditional_headersc Cs|p|j}|j|kr(tjd|j|ƒdSt|jƒ}|dk rfd|krf|djƒrft|dƒt|ƒkrfdS|j |jƒ}|j |ƒ}|j |j ƒ} tjd| ƒd} d|kr®d} tjdƒd|krÄd} tjd ƒ| rê|j j | ƒrêtjd ƒ|j j| ƒ| ròdSd |j d d ƒk�rtjdƒdS|j�rLd|k�rLtjdƒ|j j| |jj|||d�ƒn´|jdk�r|tjdƒ|j j| |jj||ƒƒn„d|k�rd|k�rÆ|ddk�rÆtjdƒ|j j| |jj|||d�ƒn:d|k�r|d�rtjdƒ|j j| |jj|||d�ƒdS)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<Úisdigitr2ÚlenrEr,rIrr3rMrÚsetrÚdumps) rrRÚresponsercrrÚresponse_headersÚcc_reqrSr,Úno_storerrrÚcache_response÷s^                      zCacheController.cache_responsecsv|j|jƒ}|jj||jj|ƒƒ}|s*|Sdg‰|jjt‡fdd„|jj ƒDƒƒƒd|_ |jj ||jj ||ƒƒ|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. zcontent-lengthc3s&|]\}}|jƒˆkr||fVqdS)N)r!)Ú.0ÚkÚv)Úexcluded_headersrrú lsz9CacheController.update_cached_response..r) r,rIrrJrr3r<ÚupdateÚdictÚitemsrLrfrg)rrRrhr,Úcached_responser)rprÚupdate_cached_responseRs   z&CacheController.update_cached_response)NTNN)NN) r;Ú __module__Ú __qualname__Ú__doc__rÚ classmethodr+r,rEr]r`rlrvrrrrrs   6o [r)ryÚloggingÚrerOrNÚ email.utilsrZpip._vendor.requests.structuresrrrÚ serializerÚ getLoggerr;r7Úcompiler rÚobjectrrrrrÚs