
    q"h?              	       B   S r SSKrSSKrSSKrSSK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  SSKJr  SSKJrJrJrJrJrJrJrJrJrJrJr  SSKJr  SSK J!r!  SS	K"J#r#J$r$  SS
K%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK3J4r4  SSK5J6r6J7r7J8r8  \Rr                  " \:5      r;\\<\<4   r=S\<S\\<   4S jr> " S S\?5      r@S\!SS4S jrA " S S\?5      rBS\<S\,SS4S jrCS\<S\,S\!4S jrDS \=S\\<   4S! jrE " S" S#5      rF " S$ S%\5      rGS&\GS\G4S' jrH\HS(S)S\\(   4S* j5       rI\" S+S,9 " S- S)5      5       rJ " S. S/\5      rK S<S0\(S1\\<\?4   S2\\S3      SS4S4 jjrL S=S\!S5\MS\J4S6 jjrNS0\(S\,S\S)   4S7 jrO " S8 S9\5      rP " S: S;5      rQg)>zO
The main purpose of this module is to expose LinkCollector.collect_sources().
    N)	dataclass)
HTMLParser)Values)CallableDictIterableListMutableMapping
NamedTupleOptionalProtocolSequenceTupleUnion)requests)Response)
RetryErrorSSLError)NetworkConnectionError)Link)SearchScope)
PipSession)raise_for_status)is_archive_fileredact_auth_from_url)vcs   )CandidatesFromPage
LinkSourcebuild_sourceurlreturnc                     [         R                   H?  nU R                  5       R                  U5      (       d  M)  U [	        U5         S;   d  M=  Us  $    g)z_Look for VCS schemes in the URL.

Returns the matched VCS scheme, or None if there's no match.
z+:N)r   schemeslower
startswithlen)r"   schemes     O/var/www/html/env/lib/python3.13/site-packages/pip/_internal/index/collector.py_match_vcs_schemer+   3   sC    
 ++99;!!&))c#f+.>$.FM      c                   8   ^  \ rS rSrS\S\SS4U 4S jjrSrU =r$ )_NotAPIContent>   content_typerequest_descr#   Nc                 <   > [         TU ]  X5        Xl        X l        g N)super__init__r0   r1   )selfr0   r1   	__class__s      r*   r5   _NotAPIContent.__init__?   s    4((r,   )r0   r1   )__name__
__module____qualname____firstlineno__strr5   __static_attributes____classcell__r7   s   @r*   r.   r.   >   s"    )S ) ) ) )r,   r.   responsec                     U R                   R                  SS5      nUR                  5       nUR                  S5      (       a  g[	        XR
                  R                  5      e)z
Check the Content-Type header to ensure the response contains a Simple
API Response.

Raises `_NotAPIContent` if the content type is not a valid content-type.
Content-TypeUnknown)z	text/htmlz#application/vnd.pypi.simple.v1+html#application/vnd.pypi.simple.v1+jsonN)headersgetr&   r'   r.   requestmethod)rA   r0   content_type_ls      r*   _ensure_api_headerrK   E   s^     ##''	BL!'')N  	
  	
'7'7'>'>
??r,   c                       \ rS rSrSrg)_NotHTTP[    N)r9   r:   r;   r<   r>   rO   r,   r*   rM   rM   [   s    r,   rM   sessionc                     [         R                  R                  U 5      u  p#pEnUS;  a
  [        5       eUR	                  U SS9n[        U5        [        U5        g)z
Send a HEAD request to the URL, and ensure the response contains a simple
API Response.

Raises `_NotHTTP` if the URL is not available for a HEAD request, or
`_NotAPIContent` if the content type is not a valid content type.
>   httphttpsT)allow_redirectsN)urllibparseurlsplitrM   headr   rK   )r"   rP   r)   netlocpathqueryfragmentresps           r*   _ensure_api_responser^   _   sR     -3LL,A,A#,F)FD&&j<<T<2DTtr,   c                    [        [        U 5      R                  5      (       a	  [        XS9  [        R                  S[        U 5      5        UR                  U SR                  / SQ5      SS.S9n[        U5        [        U5        [        R                  S[        U 5      UR                  R                  S	S
5      5        U$ )a5  Access an Simple API response with GET, and return the response.

This consists of three parts:

1. If the URL looks suspiciously like an archive, send a HEAD first to
   check the Content-Type is HTML or Simple API, to avoid downloading a
   large file. Raise `_NotHTTP` if the content type cannot be determined, or
   `_NotAPIContent` if it is not HTML or a Simple API.
2. Actually perform the request. Raise HTTP exceptions on network failures.
3. Check the Content-Type header to make sure we got a Simple API response,
   and raise `_NotAPIContent` otherwise.
rP   zGetting page %sz, )rE   z*application/vnd.pypi.simple.v1+html; q=0.1ztext/html; q=0.01z	max-age=0)AcceptzCache-Control)rF   zFetched page %s as %srC   rD   )r   r   filenamer^   loggerdebugr   rG   joinr   rK   rF   )r"   rP   r]   s      r*   _get_simple_responserf   q   s     tCy))**S2
LL"$8$=>;;ii( )+
  D4 T t
LLS!3 Kr,   rF   c                     U (       aO  SU ;   aI  [         R                  R                  5       nU S   US'   UR                  S5      nU(       a  [	        U5      $ g)z=Determine if we have any encoding information in our headers.rC   zcontent-typecharsetN)emailmessageMessage	get_paramr=   )rF   mrh   s      r*   _get_encoding_from_headersrn      sK    >W,MM!!##N3.++i(w<r,   c                   >    \ rS rSrS	S jrS\S\4S jrS\4S jr	Sr
g)
CacheablePageContent   r#   Nc                 6    UR                   (       d   eXl        g r3   )cache_link_parsingpager6   rt   s     r*   r5   CacheablePageContent.__init__   s    &&&&	r,   otherc                     [        U[        U 5      5      =(       a-    U R                  R                  UR                  R                  :H  $ r3   )
isinstancetypert   r"   )r6   rw   s     r*   __eq__CacheablePageContent.__eq__   s-    %d,P%**..1PPr,   c                 @    [        U R                  R                  5      $ r3   )hashrt   r"   r6   s    r*   __hash__CacheablePageContent.__hash__   s    DIIMM""r,   )rt   )rt   IndexContentr#   N)r9   r:   r;   r<   r5   objectboolr{   intr   r>   rO   r,   r*   rp   rp      s)    QF Qt Q## #r,   rp   c                   ,    \ rS rSrSSS\\   4S jrSrg)
ParseLinks   rt   r   r#   c                     g r3   rO   ru   s     r*   __call__ParseLinks.__call__   s    r,   rO   N)r9   r:   r;   r<   r   r   r   r>   rO   r,   r*   r   r      s    C^CCr,   r   fnc                    ^ ^ [         R                  " SS9S[        S[        [           4U 4S jj5       m[         R
                  " T 5      SSS[        [           4U U4S jj5       nU$ )	z
Given a function that parses an Iterable[Link] from an IndexContent, cache the
function's result (keyed by CacheablePageContent), unless the IndexContent
`page` has `page.cache_link_parsing == False`.
N)maxsizecacheable_pager#   c                 :   > [        T" U R                  5      5      $ r3   )listrt   )r   r   s    r*   wrapper*with_cached_index_content.<locals>.wrapper   s    B~**+,,r,   rt   r   c                 j   > U R                   (       a  T" [        U 5      5      $ [        T" U 5      5      $ r3   )rs   rp   r   )rt   r   r   s    r*   wrapper_wrapper2with_cached_index_content.<locals>.wrapper_wrapper   s+    ""/566BtH~r,   )	functools	lru_cacherp   r	   r   wraps)r   r   r   s   ` @r*   with_cached_index_contentr      sl     &- 4 -d - '- __Rn d  
 r,   rt   r   c              #   ~  #    U R                   R                  5       nUR                  S5      (       ac  [        R                  " U R
                  5      nUR                  S/ 5       H,  n[        R                  " X0R                  5      nUc  M(  Uv   M.     g[        U R                  5      nU R                  =(       d    SnUR                  U R
                  R                  U5      5        U R                  nUR                  =(       d    UnUR                   H!  n	[        R                   " XUS9nUc  M  Uv   M#     g7f)zT
Parse a Simple API's Index Content, and yield its anchor elements as Link objects.
rE   filesNzutf-8)page_urlbase_url)r0   r&   r'   jsonloadscontentrG   r   	from_jsonr"   HTMLLinkParserencodingfeeddecoder   anchorsfrom_element)
rt   rJ   datafilelinkparserr   r"   r   anchors
             r*   parse_linksr      s      &&,,.N  !FGGzz$,,'HHWb)D>>$1D|J	 *
 	DHH%F}}'H
KK##H-.
((C%#H..  I<
	 !s   D;D=T)frozenc                   d    \ rS rSr% Sr\\S'   \\S'   \\   \S'   \\S'   Sr	\
\S'   S	\4S
 jrSrg)r      at  Represents one response (or page), along with its URL.

:param encoding: the encoding to decode the given content.
:param url: the URL from which the HTML was downloaded.
:param cache_link_parsing: whether links parsed from this page's url
                           should be cached. PyPI index urls should
                           have this set to False, for example.
r   r0   r   r"   Trs   r#   c                 ,    [        U R                  5      $ r3   )r   r"   r   s    r*   __str__IndexContent.__str__  s    #DHH--r,   rO   N)r9   r:   r;   r<   __doc__bytes__annotations__r=   r   rs   r   r   r>   rO   r,   r*   r   r      s:     Nsm	H##. .r,   c                      ^  \ rS rSrSrS\SS4U 4S jjrS\S\\\\	\   4      SS4S	 jr
S\\\\	\   4      S\	\   4S
 jrSrU =r$ )r   i  zZ
HTMLParser that keeps the first base HREF and a list of all anchor
elements' attributes.
r"   r#   Nc                 H   > [         TU ]  SS9  Xl        S U l        / U l        g )NT)convert_charrefs)r4   r5   r"   r   r   )r6   r"   r7   s     r*   r5   HTMLLinkParser.__init__  s&    $/'+79r,   tagattrsc                     US:X  a)  U R                   c  U R                  U5      nUb  X0l         g g US:X  a%  U R                  R                  [	        U5      5        g g )Nbasea)r   get_hrefr   appenddict)r6   r   r   hrefs       r*   handle_starttagHTMLLinkParser.handle_starttag  sR    &=T]]2=='D $  CZLLU, r,   c                 .    U H  u  p#US:X  d  M  Us  $    g )Nr   rO   )r6   r   namevalues       r*   r   HTMLLinkParser.get_href&  s     KDv~ ! r,   )r   r   r"   )r9   r:   r;   r<   r   r=   r5   r	   r   r   r   r   r>   r?   r@   s   @r*   r   r     sx    
:C :D :-3 -tE#x}:L4M/N -SW -d5hsm);#<= (3-  r,   r   r   reasonmeth).Nc                 <    Uc  [         R                  nU" SX5        g )Nz%Could not fetch URL %s: %s - skipping)rc   rd   )r   r   r   s      r*   _handle_get_simple_failr   -  s    
 |||	0$?r,   rs   c                     [        U R                  5      n[        U R                  U R                  S   UU R                  US9$ )NrC   )r   r"   rs   )rn   rF   r   r   r"   )rA   rs   r   s      r*   _make_index_contentr   7  sE     *(*:*:;H(LL- r,   c                   U R                   R                  SS5      S   n[        U5      nU(       a  [        R	                  SUU 5        g [
        R                  R                  U5      u  pEn    nUS:X  a  [        R                  R                  [
        R                  R                  U5      5      (       aQ  UR                  S5      (       d  US-  n[
        R                  R                  US5      n[        R                  SU5         [!        X!S	9n[#        XpR$                  S
9$ ! [&         a    [        R	                  SU 5         g [(         a6  n[        R	                  SU UR*                  UR,                  5         S nAg S nAf[.         a  n[1        X5         S nAg S nAf[2         a  n[1        X5         S nAg S nAf[4         a2  nSn	U	[7        U5      -  n	[1        X	[        R8                  S9   S nAg S nAf[:        R<                   a  n[1        U SU 35         S nAg S nAf[:        R>                   a    [1        U S5         g f = f)N#r   r   zICannot look at %s URL %s because it does not support lookup as web pages.r   /z
index.htmlz# file: URL is directory, getting %sr`   )rs   z`Skipping page %s because it looks like an archive, and cannot be checked by a HTTP HEAD request.zSkipping page %s because the %s request got Content-Type: %s. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/htmlz4There was a problem confirming the ssl certificate: )r   zconnection error: z	timed out) r"   splitr+   rc   warningrU   rV   urlparseosrZ   isdirrH   url2pathnameendswithurljoinrd   rf   r   rs   rM   r.   r1   r0   r   r   r   r   r=   infor   ConnectionErrorTimeout)
r   rP   r"   
vcs_schemer)   _rZ   r]   excr   s
             r*   _get_index_contentr   D  s   
((..a
 
#C #3'JW	

   &||44S9FtQ1BGGMM&..*E*Ed*KLL ||C  3JC
 ll""35:C@U#C9: #4<S<STT9  
1	
8 /  
A 	
 	
,  " +**   +**   @G#c(6;;?  ## B(:3%&@AA
 	  3k2 	3sT   	D$ $ I	I,F  IFI*F::I(G44IH#IIc                   B    \ rS rSr% \\\      \S'   \\\      \S'   Srg)CollectedSourcesi  
find_links
index_urlsrO   N)	r9   r:   r;   r<   r   r   r    r   r>   rO   r,   r*   r   r     s"    *-..*-..r,   r   c            
           \ rS rSrSrS\S\SS4S jr\ SS\S\	S	\
SS 4S
 jj5       r\S\\   4S j5       rS\S\\   4S jrS\S\S\4S jrSrg)LinkCollectori  z
Responsible for collecting Link objects from all configured locations,
making network requests as needed.

The class's main method is its collect_sources() method.
rP   search_scoper#   Nc                     X l         Xl        g r3   r   rP   )r6   rP   r   s      r*   r5   LinkCollector.__init__  s    
 )r,   optionssuppress_no_indexc                 D   UR                   /UR                  -   nUR                  (       a5  U(       d.  [        R	                  SSR                  S U 5       5      5        / nUR                  =(       d    / n[        R                  " UUUR                  S9n[        UUS9nU$ )z
:param session: The Session to use to make requests.
:param suppress_no_index: Whether to ignore the --no-index option
    when constructing the SearchScope object.
zIgnoring indexes: %s,c              3   8   #    U  H  n[        U5      v   M     g 7fr3   r   ).0r"   s     r*   	<genexpr>'LinkCollector.create.<locals>.<genexpr>  s     Ijs-c22js   )r   r   no_index)rP   r   )
	index_urlextra_index_urlsr   rc   rd   re   r   r   creater   )clsrP   r   r   r   r   r   link_collectors           r*   r   LinkCollector.create  s     ''(7+C+CC
$5LL&IjII J ''-2
"))!!%%

 '%
 r,   c                 .    U R                   R                  $ r3   )r   r   r   s    r*   r   LinkCollector.find_links  s      +++r,   locationc                 (    [        XR                  S9$ )z.
Fetch an HTML page containing package links.
r`   )r   rP   )r6   r   s     r*   fetch_responseLinkCollector.fetch_response  s     "(LLAAr,   project_namecandidates_from_pagec                   ^ ^^ [         R                  " UUU 4S jT R                  R                  T5       5       5      R	                  5       n[         R                  " UUU 4S jT R
                   5       5      R	                  5       n[        R                  [        R                  5      (       a  [        R                  " XC5       Vs/ s H&  nUc  M  UR                  c  M  SUR                   3PM(     nn[        U5       ST S3/U-   n[        R                  SR                  U5      5        [!        [#        U5      [#        U5      S9$ s  snf )Nc           
   3   h   >#    U  H'  n[        UTTR                  R                  S S TS9v   M)     g7f)Fr  page_validator
expand_dirrs   r  Nr!   rP   is_secure_originr   locr  r  r6   s     r*   r   0LinkCollector.collect_sources.<locals>.<genexpr>  s?      
4
 P %9#||<< #() P   /2c           
   3   h   >#    U  H'  n[        UTTR                  R                  S S TS9v   M)     g7f)Tr  Nr	  r  s     r*   r   r    s=      
5
 ' %9#||<<#') 'r  z* z' location(s) to search for versions of :
)r   r   )collectionsOrderedDictr   get_index_urls_locationsvaluesr   rc   isEnabledForloggingDEBUG	itertoolschainr   r(   rd   re   r   r   )r6   r  r  index_url_sourcesfind_links_sourcessliness   ```    r*   collect_sourcesLinkCollector.collect_sources  s8    (33 
4
 ((AA,O
4
 

 &( 	 )44 
5
 
5
 

 &( 	 w}}-- #);OOA %&VV "QVVHO   u:, ##/.3 E LL5)*./-.
 	
s   EE!Er   )F)r9   r:   r;   r<   r   r   r   r5   classmethodr   r   r   propertyr	   r=   r   r   r   r   r   r   r   r  r>   rO   r,   r*   r   r     s     " 
	 
 #(	   	
 
 B ,DI , ,Bt B0F B,
,
 1,
 
	,
r,   r   r3   )T)Rr   r  email.messageri   r   r  r   r  r   urllib.parserU   urllib.requestdataclassesr   html.parserr   optparser   typingr   r   r   r	   r
   r   r   r   r   r   r   pip._vendorr   pip._vendor.requestsr   pip._vendor.requests.exceptionsr   r   pip._internal.exceptionsr   pip._internal.models.linkr   !pip._internal.models.search_scoper   pip._internal.network.sessionr   pip._internal.network.utilsr   pip._internal.utils.filetypesr   pip._internal.utils.miscr   pip._internal.vcsr   sourcesr   r    r!   	getLoggerr9   rc   r=   ResponseHeadersr+   	Exceptionr.   rK   rM   r^   rf   rn   rp   r   r   r   r   r   r   r   r   r   r   r   rO   r,   r*   <module>r9     s7         	   ! "     ! ) @ ; * 9 4 8 9 9 ! A A			8	$ c*3 8C= )Y )@ @d @,	y 	c J 4 $<c <J <8 <~ HSM 	# 	#D D*  ( n $  8 $. . .(Z > +/@
@#y.!@ 8I&
'@ 
	@ 48

,0

:T :z :h~>V :z/z /
h
 h
r,   