
    q"hJ                    ,   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
JrJrJr  SSKJr  SSKJrJr  SSKJr  \(       a  SS	K
Jr  SS
KJr  SSKJr  SSKJr  \R6                  " \5      r\R<                  " S5      rSr SS jr! " S S5      r"g)z7
The httplib2 algorithms ported for use with requests.
    )annotationsN)parsedate_tz)TYPE_CHECKING
CollectionMapping)CaseInsensitiveDict)	DictCacheSeparateBodyBaseCache)
Serializer)Literal)PreparedRequest)HTTPResponse)	BaseCachez9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)-  4  c                    [         R                  U 5      nUc   eUR                  5       nUS   US   US   US   US   4$ )z{Parses a URI using the regex given in Appendix B of RFC 3986.

(scheme, authority, path, query, fragment) = parse_uri(uri)
               )URImatchgroups)urir   r   s      U/var/www/html/env/lib/python3.13/site-packages/pip/_vendor/cachecontrol/controller.py	parse_urir   '   sM    
 IIcNE\\^F1Ivay&)VAYq	BB    c                      \ rS rSrSr    S       SS jjr\SS j5       r\SS j5       rSS jr	SS jr
SS	 jrSS
 jr  S           SS jjr  S         SS jjr      SS jrSrg)CacheController2   z4An interface to see if request should cached or not.Nc                    Uc
  [        5       OUU l        X l        U=(       d
    [        5       U l        U=(       d    SU l        g )N)      i,  r   r   )r	   cachecache_etagsr   
serializercacheable_status_codes)selfr%   r&   r'   status_codess        r   __init__CacheController.__init__5   s5     %*MY[u
&$4
&2&O6O#r   c                   [        U5      u  p#pEnU(       a  U(       d  [        SU-  5      eUR                  5       nUR                  5       nU(       d  SnU=(       a    SR                  XE/5      =(       d    UnUS-   U-   U-   nU$ )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_uris	            r   _urlnormCacheController._urlnormA   s~     6?s^2DYFLMMOO%	D 7$ 7?4e^i/+=
r   c                $    U R                  U5      $ )N)r;   )r3   r   s     r   	cache_urlCacheController.cache_urlU   s    ||C  r   c                   [         S4[         S4[         S4SSSSSSSS[         S4S.nUR                  SUR                  SS5      5      n0 nUR                  S5       H}  nUR                  5       (       d  M  UR                  S	S
5      nUS   R                  5       n X'   u  pU(       a  U	(       d  S XG'   U(       d  Ma   U" US
   R                  5       5      XG'   M     U$ ! [         a    [
        R                  SU5         M  f = f! [         a$    U	(       a  [
        R                  SU5         M   M  [         a&    [
        R                  SUUR                  5         GM  f = f)NTF)NF)max-agez	max-stale	min-freshno-cacheno-storezno-transformzonly-if-cachedzmust-revalidatepublicprivatezproxy-revalidatezs-maxagezcache-controlzCache-Control ,=r   r   z,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requireds
             r   parse_cache_control#CacheController.parse_cache_controlY   sg    T{ut%%)+,#$ -d
  [['++or2RS
(*&,,S1L%%'' &&sA.Ea(I 0 ;
 h$(!s(+E!HNN,<(=F%# 2> -  KYW " N%  
 " LLU! s*   C ?D  DD'E#4*E#"E#c                   SUR                   ;   a  gUR                  nUc   eU R                  R                  U5      nUc  [        R                  S5        g[        U R                  [        5      (       a  U R                  R                  U5      nOSnU R                  R                  XU5      nUc  [        R                  S5        U$ )z?
Load a cached response, or return None if it's not available.
RangeNzNo cache entry availablez1Cache entry deserialization failed, entry ignored)rT   urlr%   rK   rO   rP   
isinstancer
   get_bodyr'   loadswarning)r)   requestr>   
cache_data	body_fileresults         r   _load_from_cache CacheController._load_from_cache   s     goo%KK	$$$ZZ^^I.
LL34djj"788

++I6II&&wIF>NNNOr   c                0   UR                   c   eU R                  UR                   5      n[        R                  SU5        U R	                  UR
                  5      nSU;   a  [        R                  S5        gSU;   a  US   S:X  a  [        R                  S5        gU R                  U5      nU(       d  g[        UR                  5      [        ;   a  S	n[        R                  U5        U$ [        UR
                  5      nU(       a  S
U;  aL  SU;  a0  [        R                  S5        U R                  R                  U5        [        R                  S5        g[        R                  " 5       n[        US
   5      nUc   e[        R                   " USS 5      n	[#        SXy-
  5      n
[        R                  SU
5        U R	                  U5      nSnUR%                  S5      nUb  Un[        R                  SU5        OUSU;   aO  [        US   5      nUb>  [        R                   " USS 5      U	-
  n[#        SU5      n[        R                  SU5        UR%                  S5      nUb  Un[        R                  SU5        UR%                  S5      nUb  U
U-  n
[        R                  SU
5        X:  a-  [        R                  S5        [        R                  SX5        U$ SU;  a0  [        R                  S5        U R                  R                  U5        g)zM
Return a cached response if it exists in the cache, otherwise
return False.
NzLooking up "%s" in the cacherC   z-Request header has "no-cache", cache bypassedFrA   r   z1Request header has "max_age" as 0, cache bypassedzQReturning cached permanent redirect response (ignoring date and etag information)dateetagz(Purging cached response: no date or etagz!Ignoring cached response: no dater   zCurrent age based on date: %iz#Freshness lifetime from max-age: %iexpiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %irB   z'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)ra   r>   rO   rP   r]   rT   rj   rJ   statusPERMANENT_REDIRECT_STATUSESr   r%   deletetimer   calendartimegmmaxrK   )r)   rf   r>   ccrespmsgrT   now
time_tuplerm   current_ageresp_ccfreshness_lifetimemax_agero   expire_time	min_freshs                    r   cached_requestCacheController.cached_request   s   
 {{&&&NN7;;/	3Y?%%goo6 LLHI?r)}1LLLM $$W- t{{::7  LLK,?,M&/W$ GH

!!),LL<=iik!'&/2
%%%z"1~.!SZ(4kB **73  ++i(!(LL>@RS '!"79#56G"&oogbqk:TA%(K%8"BDVW &&#!(LL=?Q FF;'	 9$KLLBKP +LLMNLL$6DK  LLOPJJi( r   c                    U R                  U5      n0 nU(       a1  [        UR                  5      nSU;   a  US   US'   SU;   a  US   US'   U$ )Nrn   ETagzIf-None-Matchzlast-modifiedzLast-ModifiedzIf-Modified-Since)rj   r   rT   )r)   rf   rx   new_headersrT   s        r   conditional_headers#CacheController.conditional_headers  s\    $$W-0CDLL0QG /6vO,')3:?3K/0r   c                V   [        U R                  [        5      (       aU  U R                  R                  UU R                  R                  X#S5      US9  Ub  U R                  R                  X5        ggU R                  R                  UU R                  R                  X#U5      US9  g)z
Store the data in the cache.
r   )ro   N)rb   r%   r
   setr'   dumpsset_body)r)   r>   rf   responsebodyexpires_times         r   
_cache_setCacheController._cache_set&  s     djj"788 JJNN%%g=$   

##I4   JJNN%%g>$  r   c                *   [        U[        R                  5      (       a  U" 5       nUc  gOUnU=(       d    U R                  nUR                  U;  a"  [
        R                  SUR                  U5        g[        UR                  5      nSU;   a-  [        US   5      nUc   e[        R                  " USS 5      n	OSn	Ub:  SU;   a4  US   R                  5       (       a  [        US   5      [        U5      :w  a  gU R                  UR                  5      n
U R                  U5      nUR                   c   eU R#                  UR                   5      n[
        R                  SU5        SnS	U;   a  S
n[
        R                  S5        S	U
;   a  S
n[
        R                  S5        U(       aP  U R$                  R'                  U5      (       a0  [
        R                  S5        U R$                  R)                  U5        U(       a  gSUR'                  SS5      ;   a  [
        R                  S5        gU R*                  (       a  SU;   a  SnUR'                  S5      (       a-  [        US   5      nUb  [        R                  " USS 5      U	-
  n[-        US5      n[
        R                  SU S35        [
        R                  S5        U R/                  XXSU5        g[        UR                  5      [0        ;   a)  [
        R                  S5        U R/                  XUS5        gSU;   a  [        US   5      nUc   e[        R                  " USS 5      n	UR'                  S5      nUb3  US:  a-  [
        R                  S5        UnU R/                  UUUUU5        gSU;   au  US   (       aj  [        US   5      nUb  [        R                  " USS 5      U	-
  nOSn[
        R                  SR3                  U5      5        U R/                  UUUUU5        gggg)zK
Algorithm for caching requests.

This assumes a requests Response object.
NzStatus code %s not in %srm   r   r   content-lengthz&Updating cache with response from "%s"FrD   TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyrG   zResponse header has "Vary: *"rn   ro   i u zetag object cached for z secondszCaching due to etagzCaching permanent redirectr   rA   z'Caching b/c date exists and max-age > 0z4Caching b/c of expires header. expires in {} seconds)rb   weakrefReferenceTyper(   rp   rO   rP   r   rT   r   rt   ru   isdigitrJ   lenr]   ra   r>   r%   rK   rr   r&   rv   r   rq   format)r)   rf   response_or_refr   r*   r   r(   response_headersr{   rm   cc_reqrw   r>   no_storer   ro   r   s                    r   cache_responseCacheController.cache_responseD  s    ow'<'<==&(H 	   'H ".!L1L1L??"88LL*HOO=S 5H6
 %%%&6v&>?J)))??:bq>2DD  $44 !12::<<$%5673t9D))'//:%%&67{{&&&NN7;;/	=yI HLL9:HLL89

y11LLKLJJi( "&&vr22LL89 *: :L##I..&'7	'BC&#+??72A;#?$#FL|Z8LLL2<.IJLL./OOIM !%@@LL56OOI#>
 ''%&6v&>?J)))??:bq>2DffY'G"w{FG&  ..#I.*+;I+FGG*'/wr{'Cd'J'+LLNUU(
 OO! $ / /' (r   c                   UR                   c   eU R                  UR                   5      nU R                  U5      nU(       d  U$ S/nUR                  R	                  UR                  R                  5        VVs0 s H  u  pgUR                  5       U;  d  M  Xg_M     snn5        SUl        U R                  X1U5        U$ s  snnf )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.
r   r#   )	ra   r>   rj   rT   updateitemsr1   rp   r   )r)   rf   r   r>   cached_responseexcluded_headerskvs           r   update_cached_response&CacheController.update_cached_response  s     {{&&&NN7;;/	//8O --&& %,,2244DA779$44 4	
 "% 		O<s   :C
C
)r%   r&   r(   r'   )NTNN)r%   zBaseCache | Noner&   boolr'   zSerializer | Noner*   Collection[int] | None)r   strreturnr   )rT   zMapping[str, str]r   zdict[str, int | None])rf   r   r   zHTTPResponse | None)rf   r   r   zHTTPResponse | Literal[False])rf   r   r   zdict[str, str])NN)r>   r   rf   r   r   r   r   bytes | Noner   z
int | Noner   None)
rf   r   r   z2HTTPResponse | weakref.ReferenceType[HTTPResponse]r   r   r*   r   r   r   )rf   r   r   r   r   r   )rS   
__module____qualname____firstlineno____doc__r+   classmethodr;   r>   r]   rj   r   r   r   r   r   __static_attributes__ r   r   r    r    2   s,   > #' (,/3
P
P 
P &	
P
 -
P  & ! !4l4l\( "#' ! 	
  ! 
D "/3Q Q LQ 	Q
 -Q 
Qf(&(2>(	(r   r    )r   r   r   ztuple[str, str, str, str, str])#r   
__future__r   rt   loggingrers   r   email.utilsr   typingr   r   r   pip._vendor.requests.structuresr   pip._vendor.cachecontrol.cacher	   r
   "pip._vendor.cachecontrol.serializer   r   pip._vendor.requestsr   pip._vendor.urllib3r   r   	getLoggerrS   rO   compiler   rq   r   r    r   r   r   <module>r      sv   
 #   	   $ 5 5 ? K 9408			8	$jjMN( CM Mr   