
    5>i?                       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	r	SSK
r
SSKrSSKJrJrJ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  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,J-r-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5J6r6J7r7  \	Rp                  " \95      r:\\;\;4   r<S3S jr= " S S\>5      r?S4S jr@ " S S\>5      rAS5S jrBS6S jrCS7S jrD " S  S!5      rE " S" S#\5      rFS8S$ jrG\GS9S& j5       rH\" S'S(9 " S) S%5      5       rI " S* S+\5      rJ S:       S;S, jjrK S<     S=S- jjrLS>S. jrM " S/ S0\5      rN " S1 S25      rOg)?zO
The main purpose of this module is to expose LinkCollector.collect_sources().
    )annotationsN)IterableMutableMappingSequence)	dataclass)
HTMLParser)Values)Callable
NamedTupleProtocol)requests)Response)
RetryErrorSSLError)NetworkConnectionError)Link)SearchScope)
PipSession)raise_for_status)is_archive_fileredact_auth_from_url)url_to_path)vcs   )CandidatesFromPage
LinkSourcebuild_sourcec                    [         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)urlschemes     \/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pip/_internal/index/collector.py_match_vcs_schemer'   .   sC    
 ++99;!!&))c#f+.>$.FM      c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )_NotAPIContent9   c                <   > [         TU ]  X5        Xl        X l        g N)super__init__content_typerequest_desc)selfr0   r1   	__class__s      r&   r/   _NotAPIContent.__init__:   s    4((r(   )r0   r1   )r0   strr1   r5   returnNone)__name__
__module____qualname____firstlineno__r/   __static_attributes____classcell__r3   s   @r&   r*   r*   9   s    ) )r(   r*   c                    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)responser0   content_type_ls      r&   _ensure_api_headerrI   @   s^     ##''	BL!'')N  	
  	
'7'7'>'>
??r(   c                      \ rS rSrSrg)_NotHTTPV    N)r8   r9   r:   r;   r<   rM   r(   r&   rK   rK   V   s    r(   rK   c                    [         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urlsplitrK   headr   rI   )r$   sessionr%   netlocpathqueryfragmentresps           r&   _ensure_api_responser\   Z   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.
rV   zGetting page %sz, )rB   z*application/vnd.pypi.simple.v1+html; q=0.1ztext/html; q=0.01z	max-age=0)AcceptzCache-Control)rC   zFetched page %s as %sr@   rA   )r   r   filenamer\   loggerdebugr   rD   joinr   rI   rC   )r$   rV   r[   s      r&   _get_simple_responserd   l   s     tCy))**S2
LL"$8$=>;;ii( )+
  D4 T t
LLS!3 Kr(   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.r@   zcontent-typecharsetN)emailmessageMessage	get_paramr5   )rC   mrf   s      r&   _get_encoding_from_headersrl      sK    >W,MM!!##N3.++i(w<r(   c                  2    \ rS rSrSS jrSS jrS	S jrSrg)
CacheablePageContent   c                6    UR                   (       d   eXl        g r-   )cache_link_parsingpager2   rr   s     r&   r/   CacheablePageContent.__init__   s    &&&&	r(   c                    [        U[        U 5      5      =(       a-    U R                  R                  UR                  R                  :H  $ r-   )
isinstancetyperr   r$   )r2   others     r&   __eq__CacheablePageContent.__eq__   s-    %d,P%**..1PPr(   c                @    [        U R                  R                  5      $ r-   )hashrr   r$   r2   s    r&   __hash__CacheablePageContent.__hash__   s    DIIMM""r(   )rr   N)rr   IndexContentr6   r7   )rx   objectr6   bool)r6   int)r8   r9   r:   r;   r/   ry   r~   r<   rM   r(   r&   rn   rn      s    Q#r(   rn   c                      \ rS rSrSS jrSrg)
ParseLinks   c                    g r-   rM   rs   s     r&   __call__ParseLinks.__call__   s    cr(   rM   Nrr   r   r6   zIterable[Link])r8   r9   r:   r;   r   r<   rM   r(   r&   r   r      s    Ar(   r   c                   ^ ^ [         R                  SU 4S jj5       m[         R                  " T 5      S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`.
c                :   > [        T" U R                  5      5      $ r-   )listrr   )cacheable_pagefns    r&   wrapper*with_cached_index_content.<locals>.wrapper   s    B~**+,,r(   c                j   > U R                   (       a  T" [        U 5      5      $ [        T" U 5      5      $ r-   )rq   rn   r   )rr   r   r   s    r&   wrapper_wrapper2with_cached_index_content.<locals>.wrapper_wrapper   s+    ""/566BtH~r(   )r   rn   r6   
list[Link])rr   r   r6   r   )	functoolscachewraps)r   r   r   s   ` @r&   with_cached_index_contentr      s@     __- - __R 
 r(   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.
rB   filesNzutf-8)page_urlbase_url)r0   r!   r"   jsonloadscontentrD   r   	from_jsonr$   HTMLLinkParserencodingfeeddecoder   anchorsfrom_element)
rr   rH   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                  Z    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
rS\S'   S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.
bytesr   r5   r0   
str | Noner   r$   Tr   rq   c                ,    [        U R                  5      $ r-   )r   r$   r}   s    r&   __str__IndexContent.__str__  s    #DHH--r(   rM   N)r6   r5   )	r8   r9   r:   r;   __doc____annotations__rq   r   r<   rM   r(   r&   r   r      s/     N	H##.r(   c                  D   ^  \ rS rSrSrSU 4S jjrSS jrS	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.
c                H   > [         TU ]  SS9  Xl        S U l        / U l        g )NT)convert_charrefs)r.   r/   r$   r   r   )r2   r$   r3   s     r&   r/   HTMLLinkParser.__init__  s&    $/$(46r(   c                    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)r2   tagattrs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   rM   )r2   r   namevalues       r&   r   HTMLLinkParser.get_href!  s     KDv~ ! r(   )r   r   r$   )r$   r5   r6   r7   )r   r5   r   list[tuple[str, str | None]]r6   r7   )r   r   r6   r   )
r8   r9   r:   r;   r   r/   r   r   r<   r=   r>   s   @r&   r   r     s    
7- r(   r   c                <    Uc  [         R                  nU" SX5        g )Nz%Could not fetch URL %s: %s - skipping)ra   rb   )r   reasonmeths      r&   _handle_get_simple_failr   (  s    
 |||	0$?r(   c                    [        U R                  5      n[        U R                  U R                  S   UU R                  US9$ )Nr@   )r   r$   rq   )rl   rC   r   r   r$   )rG   rq   r   s      r&   _make_index_contentr   2  sE     *(*:*:;H(LL- r(   c               >   U R                   R                  SS5      S   n[        U5      nU(       a  [        R	                  SUU 5        g UR                  S5      (       a~  [        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[!        X@R"                  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[/        X5         S nAg S nAf[0         a  n[/        X5         S nAg S nAf[2         a2  nSnU[5        U5      -  n[/        X[        R6                  S9   S nAg S nAf[8        R:                   a  n[/        U SU 35         S nAg S nAf[8        R<                   a    [/        U S5         g f = f)N#r   r   zICannot look at %s URL %s because it does not support lookup as web pages.zfile:/z
index.htmlz# file: URL is directory, getting %sr^   )rq   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'   ra   warningr"   osrX   isdirr   endswithrR   rS   urljoinrb   rd   r   rq   rK   r*   r1   r0   r   r   r   r   r5   infor   ConnectionErrorTimeout)r   rV   r$   
vcs_schemer[   excr   s          r&   _get_index_contentr   ?  s   
((..a
 
#C #3'JW	

  ~~g277==S1A#B#B ||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   	C; ; H	H&,EH$E44HFH(GH"G66#HHc                  *    \ rS rSr% S\S'   S\S'   Srg)CollectedSourcesi{  zSequence[LinkSource | None]
find_links
index_urlsrM   N)r8   r9   r:   r;   r   r<   rM   r(   r&   r   r   {  s    ++++r(   r   c                      \ rS rSrSr      S
S jr\ S       SS jj5       r\SS j5       r	SS jr
      S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.
c                    X l         Xl        g r-   search_scoperV   )r2   rV   r   s      r&   r/   LinkCollector.__init__  s    
 )r(   c                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r-   r   ).0r$   s     r&   	<genexpr>'LinkCollector.create.<locals>.<genexpr>  s     Ijs-c22js   )r   r   no_index)rV   r   )
	index_urlextra_index_urlsr   ra   rb   rc   r   r   creater   )clsrV   optionssuppress_no_indexr   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                  $ r-   )r   r   r}   s    r&   r   LinkCollector.find_links  s      +++r(   c                (    [        XR                  S9$ )z.
Fetch an HTML page containing package links.
r^   )r   rV   )r2   locations     r&   fetch_responseLinkCollector.fetch_response  s     "(LLAAr(   c                  ^ ^^ [         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candidates_from_pagepage_validator
expand_dirrq   project_nameNr   rV   is_secure_originr   locr  r  r2   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   ra   isEnabledForloggingDEBUG	itertoolschainr   r#   rb   rc   r   r   )r2   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   N)rV   r   r   r   r6   r7   )F)rV   r   r   r	   r   r   r6   r   )r6   z	list[str])r   r   r6   IndexContent | None)r  r5   r  r   r6   r   )r8   r9   r:   r;   r   r/   classmethodr   propertyr   r   r  r<   rM   r(   r&   r   r     s     " 
	 
 #(	   	
 
 B , ,B,
,
 1,
 
	,
r(   r   )r$   r5   r6   r   )rG   r   r6   r7   )r$   r5   rV   r   r6   r7   )r$   r5   rV   r   r6   r   )rC   ResponseHeadersr6   r   )r   r   r6   r   r   r-   )r   r   r   zstr | Exceptionr   zCallable[..., None] | Noner6   r7   )T)rG   r   rq   r   r6   r   )r   r   rV   r   r6   r  )Pr   
__future__r   r  email.messagerg   r   r  r   r  r   urllib.parserR   collections.abcr   r   r   dataclassesr   html.parserr   optparser	   typingr
   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.utils.urlsr   pip._internal.vcsr   sourcesr   r   r   	getLoggerr8   ra   r5   r"  r'   	Exceptionr*   rI   rK   r\   rd   rl   rn   r   r   r   r   r   r   r   r   r   r   rM   r(   r&   <module>r:     s   #       	  > > ! "   ! ) @ ; * 9 4 8 9 9 0 ! A A			8	$ c*)Y )@,	y 	$<~	# 	#B B(  8 $. . .(Z > (,@
@@ %@ 
	@ 48

,0

9x,z ,
h
 h
r(   