
    'j@                       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Jr  SSK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"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-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;  \	Rx                  " \=5      r>\\?\?4   r@S5S jrA " S S\B5      rCS6S jrD " S S\B5      rES7S jrF S8       S9S jjrGS:S  jrH " S! S"5      rI " S# S$\5      rJS;S% jrK\KS<S' j5       rL\" S(S)9 " S* S&5      5       rM " S+ S,\5      rN S=       S>S- jjrO S?     S@S. jjrPSS/.       SAS0 jjrQ " S1 S2\5      rR " S3 S45      rSg)BzO
The main purpose of this module is to expose LinkCollector.collect_sources().
    )annotationsN)CallableIterableMutableMappingSequence)	dataclass)
HTMLParser)Values)
NamedTupleProtocol)canonicalize_name)Response)
RetryError)ConnectionFailedErrorConnectionTimeoutErrorNetworkConnectionErrorProxyConnectionErrorSSLMissingErrorSSLVerificationError)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     U/var/www/html/KUNJ/venv/lib/python3.13/site-packages/pip/_internal/index/collector.py_match_vcs_schemer+   4   sC    
 ++99;!!&))c#f+.>$.FM      c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )_NotAPIContent?   c                <   > [         TU ]  X5        Xl        X l        g N)super__init__content_typerequest_desc)selfr4   r5   	__class__s      r*   r3   _NotAPIContent.__init__@   s    4((r,   )r4   r5   )r4   strr5   r9   returnNone)__name__
__module____qualname____firstlineno__r3   __static_attributes____classcell__r7   s   @r*   r.   r.   ?   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)responser4   content_type_ls      r*   _ensure_api_headerrM   F   s^     ##''	BL!'')N  	
  	
'7'7'>'>
??r,   c                      \ rS rSrSrg)_NotHTTP\    N)r<   r=   r>   r?   r@   rQ   r,   r*   rO   rO   \   s    r,   rO   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urlsplitrO   headr   rM   )r(   sessionr)   netlocpathqueryfragmentresps           r*   _ensure_api_responser`   `   sR     -3LL,A,A#,F)FD&&j<<T<2DTtr,   Fc                   [        [        U 5      R                  5      (       a	  [        XS9  [        R                  S[        U 5      5        SSR                  / SQ5      0nU(       a  [        R                  S5        SUS'   UR                  X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.
)rZ   zGetting page %sAcceptz, )rF   z*application/vnd.pypi.simple.v1+html; q=0.1ztext/html; q=0.01z"Refreshing package index response.z	max-age=0zCache-Control)rG   zFetched page %s as %srD   rE   )r   r   filenamer`   loggerdebugr   joinrH   r   rM   rG   )r(   rZ   force_revalidaterG   r_   s        r*   _get_simple_responserh   r   s    " tCy))**S2
LL"$8$=> 	$))
G  	9:#. ;;s;,D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.rD   zcontent-typecharsetN)emailmessageMessage	get_paramr9   )rG   mrj   s      r*   _get_encoding_from_headersrp      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 r1   )cache_link_parsingpager6   rv   s     r*   r3   CacheablePageContent.__init__   s    &&&&	r,   c                    [        U[        U 5      5      =(       a-    U R                  R                  UR                  R                  :H  $ r1   )
isinstancetyperv   r(   )r6   others     r*   __eq__CacheablePageContent.__eq__   s-    %d,P%**..1PPr,   c                @    [        U R                  R                  5      $ r1   )hashrv   r(   r6   s    r*   __hash__CacheablePageContent.__hash__   s    DIIMM""r,   )rv   N)rv   IndexContentr:   r;   )r|   objectr:   bool)r:   int)r<   r=   r>   r?   r3   r}   r   r@   rQ   r,   r*   rr   rr      s    Q#r,   rr   c                      \ rS rSrSS jrSrg)
ParseLinks   c                    g r1   rQ   rw   s     r*   __call__ParseLinks.__call__   s    cr,   rQ   Nrv   r   r:   zIterable[Link])r<   r=   r>   r?   r   r@   rQ   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      $ r1   )listrv   )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      $ r1   )ru   rr   r   )rv   r   r   s    r*   wrapper_wrapper2with_cached_index_content.<locals>.wrapper_wrapper   s+    ""/566BtH~r,   )r   rr   r:   
list[Link])rv   r   r:   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.
rF   filesNzutf-8)page_urlbase_url)r4   r%   r&   jsonloadscontentrH   r   	from_jsonr(   HTMLLinkParserencodingfeeddecoder   anchorsfrom_element)
rv   rL   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   r9   r4   
str | Noner   r(   Tr   ru   c                ,    [        U R                  5      $ r1   )r   r(   r   s    r*   __str__IndexContent.__str__
  s    #DHH--r,   rQ   N)r:   r9   )	r<   r=   r>   r?   __doc____annotations__ru   r   r@   rQ   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)r2   r3   r(   r   r   )r6   r(   r7   s     r*   r3   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)r6   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   rQ   )r6   r   namevalues       r*   r   HTMLLinkParser.get_href#  s     KDv~ ! r,   )r   r   r(   )r(   r9   r:   r;   )r   r9   r   list[tuple[str, str | None]]r:   r;   )r   r   r:   r   )
r<   r=   r>   r?   r   r3   r   r   r@   rA   rB   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)rd   re   )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$ )NrD   )r   r(   ru   )rp   rG   r   r   r(   )rK   ru   r   s      r*   _make_index_contentr   4  sE     *(*:*:;H(LL- r,   )rg   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         [        X1U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[,        [.        4 a  n[1        X5         S nAg S nAf[2        [4        4 a1  nSUR6                   3n[1        X[        R8                  S9   S nAg S nAf[:         a#  n[1        U SUR6                   35         S nAg S nAf[<         a#  n[1        U SUR6                   35         S nAg S nAf[>         a)  n[1        U [A        UR6                  5      5         S nAg S nAf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 %srZ   rg   )ru   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proxy connection error: )!r(   splitr+   rd   warningr&   osr\   isdirr   endswithrV   rW   urljoinre   rh   r   ru   rO   r.   r5   r4   r   r   r   r   r   contextinfor   r   r   r9   )r   rZ   rg   r(   
vcs_schemer_   excr   s           r*   _get_index_contentr   A  s    ((..a
 
#C #3'JW	

  ~~g277==S1A#B#B ||C  3JC
 ll""35:C@U#3C
< #4<S<STT7  
1	
6 -  
A 	
 	
*  ./ +**  !/2 @G}U6;;?  ! J(:3;;-&HII    P(@&NOO
 	 " 8c#++&677 	8sZ   
C< < I	I',EI+E;;I'F::IG%%I2HIIIc                  *    \ rS rSr% S\S'   S\S'   Srg)CollectedSourcesi  zSequence[LinkSource | None]
find_links
index_urlsrQ   N)r<   r=   r>   r?   r   r@   rQ   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S j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 r1   search_scoperZ   )r6   rZ   r   s      r*   r3   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r1   r   ).0r(   s     r*   	<genexpr>'LinkCollector.create.<locals>.<genexpr>  s     Ijs-c22js   )r   r   no_index)rZ   r   )
	index_urlextra_index_urlsr   rd   re   rf   r   r   creater   )clsrZ   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                  $ r1   )r   r   r   s    r*   r   LinkCollector.find_links  s      +++r,   Nc                    U R                   R                  nSU;   =(       d    USL=(       a    [        U5      U;   n[        UU R                   US9$ )z.
Fetch an HTML page containing package links.
z:all:Nr   )rZ   refresh_packager   r   )r6   locationpackage_namerg   should_force_revalidates        r*   fetch_responseLinkCollector.fetch_response  s_      <<77")-="= #
$ D!,/3CC 	  "LL4
 	
r,   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_dirru   project_nameNr"   rZ   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   rd   isEnabledForloggingDEBUG	itertoolschainr   r'   re   rf   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   )rZ   r   r   r   r:   r;   F)rZ   r   r   r
   r   r   r:   r   )r:   z	list[str]r1   )r  r   r  r   r:   IndexContent | None)r  r9   r
  r    r:   r   )r<   r=   r>   r?   r   r3   classmethodr   propertyr   r  r$  r@   rQ   r,   r*   r   r     s     " 
	 
 #(	   	
 
 B , , :>

,6
	
(,
,
 1,
 
	,
r,   r   )r(   r9   r:   r   )rK   r   r:   r;   )r(   r9   rZ   r   r:   r;   r&  )r(   r9   rZ   r   rg   r   r:   r   )rG   ResponseHeadersr:   r   )r   r   r:   r   r   r1   )r   r   r   zstr | Exceptionr   zCallable[..., None] | Noner:   r;   )T)rK   r   ru   r   r:   r   )r   r   rZ   r   rg   r   r:   r'  )Tr   
__future__r   r  email.messagerk   r   r  r   r  r   urllib.parserV   collections.abcr   r   r   r   dataclassesr   html.parserr	   optparser
   typingr   r   pip._vendor.packaging.utilsr   pip._vendor.requestsr   pip._vendor.requests.exceptionsr   pip._internal.exceptionsr   r   r   r   r   r   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"   	getLoggerr<   rd   r9   r*  r+   	Exceptionr.   rM   rO   r`   rh   rp   rr   r   r   r   r   r   r   r   r   r   r   rQ   r,   r*   <module>rB     s   #       	  H H ! " 
 : ) 6  + 9 4 8 9 9 0 ! A A			8	$ c*)Y )@,	y 	* #8	88 8 	8v	# 	#B B(  8 $. . .(Z > (,@
@@ %@ 
	@ 48

,0

" #	?
? ? 	?
 ?D,z ,
v
 v
r,   