
     f @                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ  ej        e          Z ej        d          Zd	Zd
 Z G d de          ZdS )z7
The httplib2 algorithms ported for use with requests.
    N)parsedate_tz)CaseInsensitiveDict   )	DictCacheSeparateBodyBaseCache)
Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)-  4  c                     t                               |                                           }|d         |d         |d         |d         |d         fS )zParses 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   s     f/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/pip/_vendor/cachecontrol/controller.py	parse_urir      sD    
 YYs^^""$$F1Ivay&)VAYq	BB    c                   p    e Zd ZdZ	 ddZed             Zed             Zd Zd Z	d	 Z
dd
ZddZd ZdS )CacheControllerz4An interface to see if request should cached or not.NTc                 ~    |t                      n|| _        || _        |pt                      | _        |pd| _        d S )N)      i,  r	   r
   )r   cachecache_etagsr   
serializercacheable_status_codes)selfr   r   r   status_codess        r   __init__zCacheController.__init__'   sC     %*MY[[[u
&$4
&2&O6O###r   c                     t          |          \  }}}}}|r|st          d|z            |                                }|                                }|sd}|rd                    ||g          p|}|dz   |z   |z   }|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_uris	            r   _urlnormzCacheController._urlnorm/   s     6?s^^2D% 	NY 	NFLMMMOO%%	 	D 7$ 7 7?4e^i/+=
r   c                 ,    |                      |          S N)r1   )r)   r   s     r   	cache_urlzCacheController.cache_urlC   s    ||C   r   c                    t           dft           dft           dfddddddddt           dfd}|                    d|                    dd                    }i }|                    d          D ]}|                                s|                    d	d
          }|d                                         }	 ||         \  }}	n+# t          $ r t
                              d|           Y |w xY w|r|	sd ||<   |r	  ||d
                                                   ||<   # t          $ r  |	rt
                              d|           Y t          $ r% t
                              d||j	                   Y 	w xY w|S )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_controlz#CacheController.parse_cache_controlG   s    T{ut%%)+,#$ -d
 
  [['++or2R2RSS
&,,S11 	 	L%%''  &&sA..Ea((I 0 ;XX   KYWWW  )h )$(y! (+E!HNN,<,<(=(=F9%%!    N%   "   LLU!      s*   6C%C*)C*9&D  'E7	*E76E7c                 v   |                      |j                  }t                              d|           |                     |j                  }d|v rt                              d           dS d|v r(|d         dk    rt                              d           dS | j                            |          }|t                              d	           dS t          | j        t                    r| j        
                    |          }nd}| j                            |||          }|st                              d
           dS t          |j                  t           v rd}t                              |           |S t#          |j                  }|rd|vrTd|vr4t                              d           | j                            |           t                              d           dS t'          j                    }	t)          j        t-          |d                             }
t/          d|	|
z
            }t                              d|           |                     |          }d}d|v r$|d         }t                              d|           n]d|v rYt-          |d                   }|Bt)          j        |          |
z
  }t/          d|          }t                              d|           d|v r#|d         }t                              d|           d|v r(|d         }||z  }t                              d|           ||k    r8t                              d           t                              d||           |S d|vr4t                              d           | j                            |           dS )ze
        Return a cached response if it exists in the cache, otherwise
        return False.
        zLooking up "%s" in the cacher8   z-Request header has "no-cache", cache bypassedFr6   r   z1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredzQReturning cached permanent redirect response (ignoring date and etag information)dateetagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %iexpiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %ir7   z'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r4   urlrD   rE   rR   rI   r   r@   
isinstancer   get_bodyr   loadswarningr?   statusPERMANENT_REDIRECT_STATUSESr   deletetimecalendartimegmr   max)r    requestr4   cc
cache_data	body_filerespmsgrI   nowrT   current_ageresp_ccfreshness_lifetimerV   expire_time	min_freshs                    r   cached_requestzCacheController.cached_request}   s   
 NN7;//	3Y???%%go66 LLHIII5??r)}11LLLMMM5 Z^^I..
LL34445dj"788 	
++I66III $$Wj)DD 	NNNOOO5 t{:::7  LLK%dl33 	&//W$$ GHHH
!!),,,LL<===5ikk|GFO<<==!S4Z((4kBBB **733  !(!3LL>@RSSSS '!!"79#566G"&og66=%(K%8%8"BDVWWW ??!#ILL=?Q   ";I9$KLLBKPPP ++LLMNNNLL$6DDDK   LLOPPPJi((( ur   c                    |                      |j                  }| j                            || j                            |                    }i }|r2t          |j                  }d|v r|d         |d<   d|v r|d         |d<   |S )NrU   ETagzIf-None-Matchzlast-modifiedzLast-ModifiedzIf-Modified-Since)r4   rW   r   rZ   r   r@   r   rI   )r    rc   r4   rg   new_headersrI   s         r   conditional_headersz#CacheController.conditional_headers   s    NN7;//	$$WdjnnY.G.GHH 	L)$,77G  /6vO,'))3:?3K/0r   c                 P   t          | j        t                    rT| j                            || j                            ||d          |           | j                            ||           dS | j                            || j                            |||          |           dS )z.
        Store the data in the cache.
        r   )rV   N)rX   r   r   setr   dumpsset_body)r    r4   rc   responsebodyexpires_times         r   
_cache_setzCacheController._cache_set  s     dj"788 	 JNN%%gx==$    
 J	400000JNN%%gx>>$      r   c                    |p| j         }|j        |vr#t                              d|j        |           dS t	          |j                  }d|v r(t          j        t          |d                             }nd}|Fd|v rB|d         	                                r(t          |d                   t          |          k    rdS |                     |j                  }|                     |          }	|                     |j                  }
t                              d|
           d}d|	v rd	}t                              d
           d|v rd	}t                              d           |rN| j                            |
          r4t                              d           | j                            |
           |rdS d|                    dd          v rt                              d           dS | j        rd|v rd}|                    d          r.t          |d                   }|t          j        |          |z
  }t'          |d          }t                              d                    |                     t                              d           |                     |
||||           dS t          |j                  t,          v r4t                              d           |                     |
||d           dS d|v rt          j        t          |d                             }d|	v rI|	d         dk    r=t                              d           |	d         }|                     |
||||           dS d|v r|d         r}t          |d                   }|t          j        |          |z
  }nd}t                              d                    |                     |                     |
||||           dS dS dS dS )zc
        Algorithm for caching requests.

        This assumes a requests Response object.
        zStatus code %s not in %sNrT   r   content-lengthz&Updating cache with response from "%s"Fr9   TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyr<   zResponse header has "Vary: *"rU   rV   i u z"etag object cached for {0} secondszCaching due to etagzCaching permanent redirectr   r6   z'Caching b/c date exists and max-age > 0z5Caching b/c of expires header. expires in {0} seconds)r   r\   rD   rE   r   rI   r`   ra   r   isdigitr?   lenrR   r4   rW   r   r@   r^   r   rb   formatr{   r]   )r    rc   rx   ry   r!   r   response_headersrT   cc_reqrd   r4   no_storerz   rV   s                 r   cache_responsezCacheController.cache_response  sb    ".!L1L?"888LL*HO=S   F.x/?@@%%%?<0@0H#I#IJJDDD  $444 !12::<< 5$%56773t99DDF))'/::%%&677NN7;//	=yIII HLL9:::HLL8999 	)
y11 	)LLKLLLJi((( 	F "&&vr2222LL8999F  9	*: : :L##I.. C&'7	'BCC&#+?7#;#;d#BL|Z88LLL=DD\RRSSSLL.///OOIw$MMMMM !!%@@@LL5666OOIw#>>>>>
 '''?<0@0H#I#IJJDB2i=1#4#4FGGG!)}      ...#I. *+;I+FGGG*'/w'?'?$'F'+LLOVV(   
 OO! $    ; ('  /. r   c                    |                      |j                  }| j                            || j                            |                    }|s|S dg|j                            t          fd|j        	                                D                                  d|_
        |                     |||           |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.
        r}   c              3   R   K   | ]!\  }}|                                 v||fV  "d S r3   )r'   ).0kvexcluded_headerss      r   	<genexpr>z9CacheController.update_cached_response.<locals>.<genexpr>  sK        Aq7799$444 A4444 r   r   )r4   rW   r   rZ   r   r@   rI   updatedictitemsr\   r{   )r    rc   rx   r4   cached_responser   s        @r   update_cached_responsez&CacheController.update_cached_response  s     NN7;//	///	9R9RSS 	O --&&    $,2244    	
 	
 	
 "% 		7O<<<r   )NTNN)NN)rH   
__module____qualname____doc__r"   classmethodr1   r4   rR   ro   rs   r{   r   r    r   r   r   r   $   s        >> KOP P P P   [& ! ! [!4 4 4ls s sj      (y y y yv& & & & &r   r   )r   loggingrer`   r_   email.utilsr   pip._vendor.requests.structuresr   r   r   r   	serializer   	getLoggerrH   rD   compiler   r]   r   objectr   r   r   r   <module>r      s   
   				   $ $ $ $ $ $ ? ? ? ? ? ? 3 3 3 3 3 3 3 3 ! ! ! ! ! ! 
	8	$	$bjMNN( C C CS S S S Sf S S S S Sr   