
    *,h @                         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y)z7
The httplib2 algorithms ported for use with requests.
    N)parsedate_tz)CaseInsensitiveDict   )	DictCacheSeparateBodyBaseCache)
Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)-  4  c                 t    t         j                  |       j                         }|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     e/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pip/_vendor/cachecontrol/controller.py	parse_urir      s?    
 YYs^""$F1Ivay&)VAYq	BB    c                   b    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y)CacheControllerz4An interface to see if request should cached or not.Nc                 t    |
t               n|| _        || _        |xs
 t               | _        |xs d| _        y )N)      i,  r	   r
   )r   cachecache_etagsr   
serializercacheable_status_codes)selfr   r   r   status_codess        r   __init__zCacheController.__init__'   s7     %*MY[u
&$4
&2&O6O#r   c                     t        |      \  }}}}}|r|st        d|z        |j                         }|j                         }|sd}|xr dj                  ||g      xs |}|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%YFLMMOO%	D 7$ 7?4e^i/+=
r   c                 $    | j                  |      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}|j                  d|j                  dd            }i }|j                  d      D ]j  }|j                         s|j                  d	d
      }|d   j                         }	 ||   \  }}	|r|	sd ||<   |sN	  ||d
   j                               ||<   l |S # t        $ r t
        j                  d|       Y w xY w# t        $ r |	rt
        j                  d|       Y t        $ r$ t
        j                  d||j                         Y w xY w)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   sf    T{ut%%)+,#$ -d
  [['++or2RS
&,,S1 	L%%' &&sA.Ea(I 0 ;X
 h$(y!(+E!HNN,<(=F9%#	> -  KYW " N% " LLU!s*   C,C1C.-C.1!E )E ?E c                    | j                  |j                        }t        j                  d|       | j	                  |j
                        }d|v rt        j                  d       yd|v r|d   dk(  rt        j                  d       y| j                  j                  |      }|t        j                  d	       yt        | j                  t              r| j                  j                  |      }nd}| j                  j                  |||      }|st        j                  d
       yt        |j                        t         v rd}t        j                  |       |S t#        |j
                        }|rd|vrJd|vr0t        j                  d       | j                  j%                  |       t        j                  d       yt'        j&                         }	t)        j*                  t-        |d               }
t/        d|	|
z
        }t        j                  d|       | j	                  |      }d}d|v r|d   }t        j                  d|       nNd|v rJt-        |d         }|:t)        j*                  |      |
z
  }t/        d|      }t        j                  d|       d|v r|d   }t        j                  d|       d|v r |d   }||z  }t        j                  d|       ||kD  r.t        j                  d       t        j                  d||       |S d|vr0t        j                  d       | j                  j%                  |       y)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?%%goo6 LLHI?r)}1LLLM ZZ^^I.
LL34djj"78

++I6II $$Wj)DNNNO t{{::7  LLK%dll3&/W$ GH

!!),LL<=iik|GFO<=!S4Z(4kB **73  !(!3LL>@RS '!"79#56G"&oog6=%(K%8"BDVW ?!#ILL=?Q ";I9$KLLBKP +LLMNLL$6DK  LLOPJJi( r   c                    | j                  |j                        }| j                  j                  || j                  j                  |            }i }|r-t        |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;;/	$$WdjjnnY.GH)$,,7G /6vO,')3:?3K/0r   c                 V   t        | j                  t              rV| j                  j                  || j                  j                  ||d      |       | j                  j                  ||       y| j                  j                  || j                  j                  |||      |       y)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     djj"78 JJNN%%gx=$  
 JJ	40JJNN%%gx>$  r   c                    |xs | j                   }|j                  |vr"t        j                  d|j                  |       yt	        |j
                        }d|v r"t        j                  t        |d               }nd}|2d|v r.|d   j                         rt        |d         t        |      k7  ry| j                  |j
                        }| j                  |      }	| j                  |j                        }
t        j                  d|
       d}d|	v rd	}t        j                  d
       d|v rd	}t        j                  d       |rK| j                  j!                  |
      r0t        j                  d       | j                  j#                  |
       |ryd|j!                  dd      v rt        j                  d       y| j$                  rd|v rd}|j!                  d      r(t        |d         }|t        j                  |      |z
  }t'        |d      }t        j                  dj)                  |             t        j                  d       | j+                  |
||||       yt        |j                        t,        v r*t        j                  d       | j+                  |
||d       yd|v rt        j                  t        |d               }d|	v r8|	d   dkD  r0t        j                  d       |	d   }| j+                  |
||||       yd|v rk|d   ret        |d         }|t        j                  |      |z
  }nd}t        j                  dj)                  |             | j+                  |
||||       yyyy)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  sM    ".!L1L1L??"88LL*HOO=S .x/?/?@%%??<0@0H#IJDD  $44 !12::<$%5673t9D))'//:%%&67NN7;;/	=yI HLL9:HLL89

y1LLKLJJi( "&&vr22LL89 *: :L##I.&'7	'BC&#+??7#;d#BL|Z8LLL=DD\RSLL./OOIw$M !%@@LL56OOIw#>
 ''??<0@0H#IJDB2i=1#4FG!)}  ..#I.*+;I+FGG*'/w'?$'F'+LLOVV(
 OO! $ / /! (r   c                 t   | j                  |j                        }| j                  j                  || j                  j                  |            }|s|S dg|j                  j                  t        fd|j                  j                         D                     d|_
        | j                  |||       |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   P   K   | ]  \  }}|j                         vr||f  y wr3   )r'   ).0kvexcluded_headerss      r   	<genexpr>z9CacheController.update_cached_response.<locals>.<genexpr>  s0      Aq779$44 As   #&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;;/	////	9RSO --&& $,,22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  & ! !4lsj (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      sc   
  	   $ ? 3 ! 
		8	$bjjMN( CSf Sr   