
    egG                       d Z ddlm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
mZmZ ddlmZ ddlmZmZ ddlmZ e
rdd	l	mZ dd
lmZ ddlmZ ddlmZ  ej4                  e      Z ej:                  d      ZdZddZ  G d d      Z!y)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                    t         j                  |       }|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)
                   )URImatchgroups)urir   r   s      /var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/pip/_vendor/cachecontrol/controller.py	parse_urir   %   sM    
 IIcNE\\^F1Ivay&)VAYq	BB    c                      e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZedd       Zedd       ZddZddZ	ddZ
dd	Z	 	 d	 	 	 	 	 	 	 	 	 	 	 dd
Z	 	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 d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__3   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)r9   )r1   r   s     r   	cache_urlzCacheController.cache_urlS   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_controlW   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                d   |j                   }|J | j                  j                  |      }|t        j	                  d       yt        | j                  t              r| j                  j                  |      }nd}| j                  j                  |||      }|t        j                  d       |S )zO
        Load a cached response, or return None if it's not available.
        NzNo cache entry availablez1Cache entry deserialization failed, entry ignored)urlr$   rG   rK   rL   
isinstancer
   get_bodyr&   loadswarning)r(   requestr;   
cache_data	body_fileresults         r   _load_from_cachez CacheController._load_from_cache   s     KK	$$$ZZ^^I.
LL34djj"78

++I6II&&w
IF>NNNOr   c                   |j                   J | 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                  |      }|s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        |d
         }|J t        j                   |dd       }	t#        d||	z
        }
t        j                  d|
       | j	                  |      }d}|j%                  d      }||}t        j                  d|       nQd|v rMt        |d         }|=t        j                   |dd       |	z
  }t#        d|      }t        j                  d|       |j%                  d      }||}t        j                  d|       |j%                  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.
        NzLooking up "%s" in the cacher?   z-Request header has "no-cache", cache bypassedFr=   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: %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[   r;   rK   rL   rY   rP   rd   rF   statusPERMANENT_REDIRECT_STATUSESr   r$   deletetimer   calendartimegmmaxrG   )r(   r`   r;   ccrespmsgrP   now
time_tuplerf   current_ageresp_ccfreshness_lifetimemax_agerh   expire_time	min_freshs                    r   cached_requestz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~.!S4Z(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                    | j                  |      }i }|r-t        |j                        }d|v r|d   |d<   d|v r|d   |d<   |S )Nrg   ETagzIf-None-Matchzlast-modifiedzLast-ModifiedzIf-Modified-Since)rd   r   rP   )r(   r`   rq   new_headersrP   s        r   conditional_headersz#CacheController.conditional_headers  s\    $$W-0CDLL0QG /6vO,')3:?3K/0r   c                \   t        | j                  t              rY| j                  j                  || j                  j                  ||d      |       || j                  j                  ||       yy| j                  j                  || j                  j                  |||      |       y)z.
        Store the data in the cache.
        r   )rh   N)r\   r$   r
   setr&   dumpsset_body)r(   r;   r`   responsebodyexpires_times         r   
_cache_setzCacheController._cache_set  s     djj"78 JJNN%%gx=$   

##It4   JJNN%%gx>$  r   c                D   |xs | j                   }|j                  |vr"t        j                  d|j                  |       yt	        |j
                        }d|v r+t        |d         }|J t        j                  |dd       }nd}|2d|v r.|d   j                         rt        |d         t        |      k7  ry| j                  |j
                        }	| 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                  |dd       |z
  }t'        |d      }t        j                  d| d       t        j                  d       | j)                  |||||       yt        |j                        t*        v r*t        j                  d       | j)                  |||d       yd|v rt        |d         }|J t        j                  |dd       }|
j!                  d      }|2|dkD  r-t        j                  d       |}| j)                  |||||       yd|v rn|d   rht        |d         }|t        j                  |dd       |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 %sNrf   r   r   content-lengthz&Updating cache with response from "%s"Fr@   TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"*varyrC   zResponse header has "Vary: *"rg   rh   i u zetag object cached for z secondszCaching due to etagzCaching permanent redirectr   r=   z'Caching b/c date exists and max-age > 0z4Caching b/c of expires header. expires in {} seconds)r'   ri   rK   rL   r   rP   r   rm   rn   isdigitrF   lenrY   r[   r;   r$   rG   rk   r%   ro   r   rj   format)r(   r`   r   r   r)   r'   response_headersrt   rf   cc_reqrp   r;   no_storer   rh   rx   s                   r   cache_responsezCacheController.cache_response=  s    ".!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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./OOIw$M !%@@LL56OOIw#>
 ''%&6v&>?J)))??:bq>2DffY'G"w{FG&  ..#I.*+;I+FGG*'/wr{'Cd'J'+LLNUU(
 OO! $ / /' (r   c                z   |j                   J | j                  |j                         }| j                  |      }|s|S dg}|j                  j	                  |j                  j                         D ci c]  \  }}|j                         |vr|| c}}       d|_        | j                  |||       |S c c}}w )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"   )	r[   r;   rd   rP   updateitemsr/   ri   r   )r(   r`   r   r;   cached_responseexcluded_headerskvs           r   update_cached_responsez&CacheController.update_cached_response  s     {{&&&NN7;;/	//8O --&& %,,224Aq779$44 1	
 "% 		7O<s   4B7
)NTNN)r$   zBaseCache | Noner%   boolr&   zSerializer | Noner)   Collection[int] | None)r   strreturnr   )rP   zMapping[str, str]r   zdict[str, int | None])r`   r   r   zHTTPResponse | None)r`   r   r   zHTTPResponse | Literal[False])r`   r   r   zdict[str, str])NN)r;   r   r`   r   r   r   r   bytes | Noner   z
int | Noner   None)
r`   r   r   r   r   r   r)   r   r   r   )r`   r   r   r   r   r   )rO   
__module____qualname____doc__r*   classmethodr9   r;   rY   rd   r{   r   r   r   r    r   r   r    r    0   s+   > #' (,/3
P
P 
P &	
P
 -
P  & ! !4l*l\( "#' ! 	
  ! 
D "/3G G G 	G
 -G 
GR(&(2>(	(r   r    )r   r   r   ztuple[str, str, str, str, str])"r   
__future__r   rm   loggingrerl   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   	getLoggerrO   rK   compiler   rj   r   r    r   r   r   <module>r      sw   
 #   	  $ 5 5 ? K 9408			8	$bjjMN( C~ ~r   