
    鴀j@                       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Zddl	Z	ddl
Z
ddlZddlmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;  e	j<        e=          Z>ee?e?f         Z@dMdZA G d deB          ZCdNd!ZD G d" d#eB          ZEdOd&ZF	 dPdQd*ZGdRd-ZH G d. d/          ZI G d0 d1e          ZJdSd3ZKeKdTd7            ZL ed89           G d: d5                      ZM G d; d<e          ZN	 dUdVdCZO	 dWdXdEZPd'dFdYdHZQ G dI dJe          ZR G dK dL          ZSdS )ZzO
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_sourceurlstrreturn
str | Nonec                    t           j        D ]D}|                                                     |          r| t	          |                   dv r|c S EdS )zgLook 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     g/workspace/show-city-briefing-agent/.venv/lib/python3.11/site-packages/pip/_internal/index/collector.py_match_vcs_schemer.   4   sW    
 +  99;;!!&)) 	c#f++.>$.F.FMMM4    c                        e Zd Zd fdZ xZS )_NotAPIContentcontent_typer$   request_descr%   Nonec                h    t                                          ||           || _        || _        d S N)super__init__r2   r3   )selfr2   r3   	__class__s      r-   r8   z_NotAPIContent.__init__@   s3    |444((r/   )r2   r$   r3   r$   r%   r4   )__name__
__module____qualname__r8   __classcell__r:   s   @r-   r1   r1   ?   s=        ) ) ) ) ) ) ) ) ) )r/   r1   responser   r4   c                    | j                             dd          }|                                }|                    d          rdS t	          || j        j                  )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*   r1   requestmethod)r@   r2   content_type_ls      r-   _ensure_api_headerrJ   F   sg     #''	BBL!''))N  	
   	
x'7'>
?
??r/   c                      e Zd ZdS )_NotHTTPN)r;   r<   r=    r/   r-   rL   rL   \   s        Dr/   rL   sessionr   c                    t           j                            |           \  }}}}}|dvrt                      |                    | d          }t          |           t          |           dS )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urlsplitrL   headr   rJ   )r#   rN   r,   netlocpathqueryfragmentresps           r-   _ensure_api_responser\   `   sq     -3L,A,A#,F,F)FFD%&&&jj<<T<22DTtr/   Fforce_revalidateboolc                   t          t          |           j                  rt          | |           t                              dt          |                      dd                    g d          i}|rt                              d           d|d<   |                    | |	          }t          |           t          |           t                              d
t          |           |j                            dd                     |S )aY  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.
    )rN   zGetting page %sAcceptz, )rD   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)rE   zFetched page %s as %srB   rC   )r   r   filenamer\   loggerdebugr   joinrF   r   rJ   rE   )r#   rN   r]   rE   r[   s        r-   _get_simple_responsere   r   s   " tCyy)** 3S'2222
LL"$8$=$=>>> 	$))  
 
G  / 	9:::#. ;;sG;,,DT t
LLS!!33   Kr/   rE   ResponseHeadersc                    | rSd| v rOt           j                                        }| d         |d<   |                    d          }|rt	          |          S dS )z=Determine if we have any encoding information in our headers.rB   zcontent-typecharsetN)emailmessageMessage	get_paramr$   )rE   mrh   s      r-   _get_encoding_from_headersrn      s`      >W,,M!!###N3.++i(( 	 w<<4r/   c                  &    e Zd ZddZdd	ZddZdS )CacheablePageContentpageIndexContentr%   r4   c                &    |j         sJ || _        d S r6   )cache_link_parsingrq   r9   rq   s     r-   r8   zCacheablePageContent.__init__   s    &&&&			r/   otherobjectr^   c                p    t          |t          |                     o| j        j        |j        j        k    S r6   )
isinstancetyperq   r#   )r9   rv   s     r-   __eq__zCacheablePageContent.__eq__   s*    %d,,P%*.1PPr/   intc                4    t          | j        j                  S r6   )hashrq   r#   r9   s    r-   __hash__zCacheablePageContent.__hash__   s    DIM"""r/   N)rq   rr   r%   r4   )rv   rw   r%   r^   )r%   r|   )r;   r<   r=   r8   r{   r   rM   r/   r-   rp   rp      sT           Q Q Q Q# # # # # #r/   rp   c                      e Zd ZddZdS )
ParseLinksrq   rr   r%   Iterable[Link]c                    d S r6   rM   ru   s     r-   __call__zParseLinks.__call__   s      r/   Nrq   rr   r%   r   )r;   r<   r=   r   rM   r/   r-   r   r      s        AAAAAAr/   r   fnc                |     t           j        d	 fd            t          j                   d
 fd            }|S )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`.
    cacheable_pagerp   r%   
list[Link]c                >    t           | j                            S r6   )listrq   )r   r   s    r-   wrapperz*with_cached_index_content.<locals>.wrapper   s    BB~*++,,,r/   rq   rr   c                r    | j         r t          |                     S t           |                     S r6   )rt   rp   r   )rq   r   r   s    r-   wrapper_wrapperz2with_cached_index_content.<locals>.wrapper_wrapper   s;    " 	77/55666BBtHH~~r/   )r   rp   r%   r   )rq   rr   r%   r   )	functoolscachewraps)r   r   r   s   ` @r-   with_cached_index_contentr      sr     _- - - - - _- _R      
 r/   rq   rr   r   c              #    K   | j                                         }|                    d          rUt          j        | j                  }|                    dg           D ]#}t          j        || j	                  }||V  $dS t          | j	                  }| j        pd}|                    | j                            |                     | j	        }|j        p|}|j        D ] }	t          j        |	||          }||V  !dS )z\
    Parse a Simple API's Index Content, and yield its anchor elements as Link objects.
    rD   filesNzutf-8)page_urlbase_url)r2   r)   r*   jsonloadscontentrF   r   	from_jsonr#   HTMLLinkParserencodingfeeddecoder   anchorsfrom_element)
rq   rI   datafilelinkparserr   r#   r   anchors
             r-   parse_linksr      s!      &,,..N  !FGG z$,''HHWb)) 	 	D>$11D|JJJJDH%%F}'H
KK##H--...
(C%#H.   #III<



	 r/   T)frozenc                  R    e Zd ZU dZded<   ded<   ded<   ded<   d	Zd
ed<   ddZdS )rr   a  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   r$   r2   r&   r   r#   Tr^   rt   r%   c                *    t          | j                  S r6   )r   r#   r   s    r-   __str__zIndexContent.__str__
  s    #DH---r/   N)r%   r$   )r;   r<   r=   __doc____annotations__rt   r   rM   r/   r-   rr   rr      sr           NNNHHH#####. . . . . .r/   c                  4     e Zd ZdZd fdZdd
ZddZ xZS )r   zf
    HTMLParser that keeps the first base HREF and a list of all anchor
    elements' attributes.
    r#   r$   r%   r4   c                v    t                                          d           || _        d | _        g | _        d S )NT)convert_charrefs)r7   r8   r#   r   r   )r9   r#   r:   s     r-   r8   zHTMLLinkParser.__init__  s7    $///$(46r/   tagattrslist[tuple[str, str | None]]c                    |dk    r)| j         "|                     |          }|	|| _         d S d S |dk    r)| j                            t	          |                     d S d S )Nbasea)r   get_hrefr   appenddict)r9   r   r   hrefs       r-   handle_starttagzHTMLLinkParser.handle_starttag  sn    &==T]2==''D $  CZZLU,,,,, Zr/   r&   c                *    |D ]\  }}|dk    r|c S d S )Nr   rM   )r9   r   namevalues       r-   r   zHTMLLinkParser.get_href#  s1      	 	KD%v~~ tr/   )r#   r$   r%   r4   )r   r$   r   r   r%   r4   )r   r   r%   r&   )r;   r<   r=   r   r8   r   r   r>   r?   s   @r-   r   r     so         
7 7 7 7 7 7- - - -       r/   r   r   r   reasonstr | ExceptionmethCallable[..., None] | Nonec                <    |t           j        } |d| |           d S )Nz%Could not fetch URL %s: %s - skipping)rb   rc   )r   r   r   s      r-   _handle_get_simple_failr   *  s+    
 ||D	0$?????r/   rt   c                |    t          | j                  }t          | j        | j        d         || j        |          S )NrB   )r   r#   rt   )rn   rE   rr   r   r#   )r@   rt   r   s      r-   _make_index_contentr   4  sG     *(*:;;H(L-   r/   )r]   IndexContent | Nonec                  | j                             dd          d         }t          |          }|rt                              d||            d S |                    d          rt          j                            t          |                    rU|
                    d          s|dz  }t          j                            |d          }t                              d|           	 t          |||	          }t!          || j        
          S # t$          $ r t                              d|            Y n-t&          $ r1}t                              d| |j        |j                   Y d }~nd }~wt,          t.          f$ r}t1          | |           Y d }~nd }~wt2          t4          f$ r0}d|j         }t1          | |t          j                   Y d }~nd }~wt:          $ r"}t1          | d|j                    Y d }~nfd }~wt<          $ r"}t1          | d|j                    Y d }~n<d }~wt>          $ r,}t1          | tA          |j                             Y d }~nd }~ww xY wd S )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rN   r]   )rt   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.   rb   warningr*   osrX   isdirr   endswithrS   rT   urljoinrc   re   r   rt   rL   r1   r3   r2   r   r   r   r   r   contextinfor   r   r   r$   )r   rN   r]   r#   
vcs_schemer[   excr   s           r-   _get_index_contentr   A  s    (..a
 
 
#C #3''J W	
 	
 	

 t ~~g 
A27==S1A1A#B#B 
A ||C   	3JC
 l""355:C@@@U#3C
 
 
< #4D<STTTT7  
 
 
1	
 	
 	
 	
 	

  
 
 
A 	
 	
 	
 	
 	
 	
 	
 	
 ./ + + +c******** /2 @ @ @UUUf6;?????????  J J J&H3;&H&HIIIIIIII P P P&N&N&NOOOOOOOO! 8 8 8c#+&6&6777777778 4sZ   (D %I"8	I"'E--I"FI"*&GI""G??I"H))I"6"II"c                  $    e Zd ZU ded<   ded<   dS )CollectedSourceszSequence[LinkSource | None]
find_links
index_urlsN)r;   r<   r=   r   rM   r/   r-   r   r     s*         ++++++++++r/   r   c                  b    e Zd ZdZddZe	 dd d            Zed!d            Z	 d"d#dZ	d$dZ
dS )%LinkCollectorz
    Responsible for collecting Link objects from all configured locations,
    making network requests as needed.

    The class's main method is its collect_sources() method.
    rN   r   search_scoper   r%   r4   c                "    || _         || _        d S r6   )r   rN   )r9   rN   r   s      r-   r8   zLinkCollector.__init__  s    
 )r/   Foptionsr
   suppress_no_indexr^   c                   |j         g|j        z   }|j        r<|s:t                              dd                    d |D                                  g }|j        pg }t          j        |||j                  }t          ||          }|S )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  4   K   | ]}t          |          V  d S r6   r   ).0r#   s     r-   	<genexpr>z'LinkCollector.create.<locals>.<genexpr>  s+      IIs-c22IIIIIIr/   )r   r   no_index)rN   r   )
	index_urlextra_index_urlsr   rb   rc   rd   r   r   creater   )clsrN   r   r   r   r   r   link_collectors           r-   r   zLinkCollector.create  s     '(7+CC
 	$5 	LL&IIjIIIII   J '-2
")!!%
 
 

 '%
 
 
 r/   	list[str]c                    | j         j        S r6   )r   r   r   s    r-   r   zLinkCollector.find_links  s     ++r/   Nlocationr   package_namer&   r   c                z    | j         j        }d|v p|duot          |          |v }t          || j         |          S )z>
        Fetch an HTML page containing package links.
        z:all:Nr   )rN   refresh_packager   r   )r9   r   r   r]   should_force_revalidates        r-   fetch_responsezLinkCollector.fetch_response  se      <7")-="= #
$ D!,//3CC 	  "L4
 
 
 	
r/   project_namer$   candidates_from_pager    r   c                z    t          j         fd j                                      D                                                       }t          j         fd j        D                                                       }t                              t          j	                  red t          j        ||          D             }t          |           d dg|z   }t                              d                    |                     t          t!          |          t!          |                    S )Nc           	   3  V   K   | ]#}t          |j        j        d d           V  $dS )Fr   page_validator
expand_dirrt   r   Nr"   rN   is_secure_originr   locr   r   r9   s     r-   r   z0LinkCollector.collect_sources.<locals>.<genexpr>  s_       
4
 
4
  %9#|< #()  
4
 
4
 
4
 
4
 
4
 
4
r/   c           	   3  V   K   | ]#}t          |j        j        d d           V  $dS )Tr   Nr   r   s     r-   r   z0LinkCollector.collect_sources.<locals>.<genexpr>  s_       
5
 
5
  %9#|<#')  
5
 
5
 
5
 
5
 
5
 
5
r/   c                4    g | ]}||j         d|j          S )Nz* )r   )r   ss     r-   
<listcomp>z1LinkCollector.collect_sources.<locals>.<listcomp>  s6       =QV%7 QV%7%7%7r/   z' location(s) to search for versions of :
)r   r   )collectionsOrderedDictr   get_index_urls_locationsvaluesr   rb   isEnabledForloggingDEBUG	itertoolschainr+   rc   rd   r   r   )r9   r   r   index_url_sourcesfind_links_sourcesliness   ```   r-   collect_sourceszLinkCollector.collect_sources  s    (3 
4
 
4
 
4
 
4
 
4
 
4
 (AA,OO
4
 
4
 
4
 

 

 &(( 	 )4 
5
 
5
 
5
 
5
 
5
 
5
 
5
 
5
 
5
 

 

 &(( 	 w}-- 
	+ ");=NOO  E u:: 3 3#/3 3 3 E LL5))***.//-..
 
 
 	
r/   )rN   r   r   r   r%   r4   F)rN   r   r   r
   r   r^   r%   r   )r%   r   r6   )r   r   r   r&   r%   r   )r   r$   r   r    r%   r   )r;   r<   r=   r   r8   classmethodr   propertyr   r   r  rM   r/   r-   r   r     s             
 #(	    [B , , , X, :>
 
 
 
 
(,
 ,
 ,
 ,
 ,
 ,
r/   r   )r#   r$   r%   r&   )r@   r   r%   r4   )r#   r$   rN   r   r%   r4   r  )r#   r$   rN   r   r]   r^   r%   r   )rE   rf   r%   r&   )r   r   r%   r   r   r6   )r   r   r   r   r   r   r%   r4   )T)r@   r   rt   r^   r%   rr   )r   r   rN   r   r]   r^   r%   r   )Tr   
__future__r   r  email.messageri   r   r  r   r  r   urllib.parserS   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;   rb   r$   rf   r.   	Exceptionr1   rJ   rL   r\   re   rn   rp   r   r   r   rr   r   r   r   r   r   r   rM   r/   r-   <module>r-     s    # " " " " "                   				     H H H H H H H H H H H H ! ! ! ! ! ! " " " " " "             
 : 9 9 9 9 9 ) ) ) ) ) ) 6 6 6 6 6 6                + * * * * * 9 9 9 9 9 9 4 4 4 4 4 4 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 0 0 0 0 0 0 ! ! ! ! ! ! A A A A A A A A A A		8	$	$ c*   ) ) ) ) )Y ) ) )@ @ @ @,	 	 	 	 	y 	 	 	   * #8 8 8 8 8v   	# 	# 	# 	# 	# 	# 	# 	#B B B B B B B B   (    8 $. . . . . . . .(    Z   > (,@ @ @ @ @ 48
 
 
 
 
" #	? ? ? ? ? ?D, , , , ,z , , ,
v
 v
 v
 v
 v
 v
 v
 v
 v
 v
r/   